Skip to content

Commit 747553c

Browse files
authored
fix: updated logic in migration ansible scripts to not error when target address already exists (#945)
1 parent 30bf9dc commit 747553c

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

patterns/roks-quickstart/scripts/migration-pre-ansible-playbook.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,27 @@
3232
for i in "${!CLUSTER_LIST[@]}"; do
3333
SOURCE="${ADDRESS_LIST}.ibm_container_vpc_cluster.cluster[\"${CLUSTER_LIST[$i]}\"]"
3434
DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_vpc_cluster.cluster[0]"
35-
if [ -n "${CLUSTER_LIST[$i]}" ]; then
35+
if [ -n "${CLUSTER_LIST[$i]}" ] && [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
3636
MOVED_PARAMS+=("$SOURCE, $DESTINATION")
3737
fi
3838
3939
ADDONS_RESOURCE=$(echo "$STATE" | jq -r --arg CLUSTER "${CLUSTER_LIST[$i]}" '.resources[] | select((.type == "ibm_container_vpc_cluster") and (.mode == "managed") and (.name == "cluster")) | .instances[] | select(.index_key == $CLUSTER) | .index_key')
4040
if [ -n "$ADDONS_RESOURCE" ]; then
4141
ADDONS_SOURCE="${ADDRESS_LIST}.ibm_container_addons.addons[\"${CLUSTER_LIST[$i]}\"]"
4242
ADDONS_DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_addons.addons"
43-
MOVED_PARAMS+=("$ADDONS_SOURCE, $ADDONS_DESTINATION")
43+
if [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
44+
MOVED_PARAMS+=("$ADDONS_SOURCE, $ADDONS_DESTINATION")
45+
fi
4446
fi
4547
4648
for x in "${!WORKER_POOLS[@]}"; do
4749
if [[ "${WORKER_POOLS[$x]}" == *"${CLUSTER_LIST[$i]}"* ]]; then
4850
pool_name=${WORKER_POOLS[$x]//"${CLUSTER_LIST[$i]}-"/}
4951
WORKER_POOL_SOURCE="${ADDRESS_LIST}.ibm_container_vpc_worker_pool.pool[\"${WORKER_POOLS[$x]}\"]"
5052
WORKER_POOL_DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_vpc_worker_pool.pool[\"$pool_name\"]"
51-
MOVED_PARAMS+=("$WORKER_POOL_SOURCE, $WORKER_POOL_DESTINATION")
53+
if [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
54+
MOVED_PARAMS+=("$WORKER_POOL_SOURCE, $WORKER_POOL_DESTINATION")
55+
fi
5256
fi
5357
done
5458
done
@@ -65,6 +69,7 @@
6569
- name: Initiate Commands List
6670
set_fact:
6771
commands: []
72+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
6873
- name: Add new JSON Objects to List
6974
set_fact:
7075
commands: "{{ commands +
@@ -75,13 +80,15 @@
7580
loop: "{{ move_list.stdout_lines }}"
7681
loop_control:
7782
index_var: count
83+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
7884
- name: Create complete JSON body
7985
set_fact:
8086
commands: "{{
8187
{ 'commands': commands ,
8288
'operation_name': 'workspace Command',
8389
'description': 'Executing command'}
8490
}}"
91+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
8592
- name: Run Terraform commands
8693
uri:
8794
url: "{{ project_url }}/v1/projects/{{ project_id }}/configs/{{ config_id }}/execute_schematics_commands"
@@ -93,3 +100,4 @@
93100
body_format: json
94101
status_code: [200, 202]
95102
register: result
103+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''

patterns/roks/scripts/migration-pre-ansible-playbook.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,27 @@
3232
for i in "${!CLUSTER_LIST[@]}"; do
3333
SOURCE="${ADDRESS_LIST}.ibm_container_vpc_cluster.cluster[\"${CLUSTER_LIST[$i]}\"]"
3434
DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_vpc_cluster.cluster[0]"
35-
if [ -n "${CLUSTER_LIST[$i]}" ]; then
35+
if [ -n "${CLUSTER_LIST[$i]}" ] && [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
3636
MOVED_PARAMS+=("$SOURCE, $DESTINATION")
3737
fi
3838
3939
ADDONS_RESOURCE=$(echo "$STATE" | jq -r --arg CLUSTER "${CLUSTER_LIST[$i]}" '.resources[] | select((.type == "ibm_container_vpc_cluster") and (.mode == "managed") and (.name == "cluster")) | .instances[] | select(.index_key == $CLUSTER) | .index_key')
4040
if [ -n "$ADDONS_RESOURCE" ]; then
4141
ADDONS_SOURCE="${ADDRESS_LIST}.ibm_container_addons.addons[\"${CLUSTER_LIST[$i]}\"]"
4242
ADDONS_DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_addons.addons"
43-
MOVED_PARAMS+=("$ADDONS_SOURCE, $ADDONS_DESTINATION")
43+
if [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
44+
MOVED_PARAMS+=("$ADDONS_SOURCE, $ADDONS_DESTINATION")
45+
fi
4446
fi
4547
4648
for x in "${!WORKER_POOLS[@]}"; do
4749
if [[ "${WORKER_POOLS[$x]}" == *"${CLUSTER_LIST[$i]}"* ]]; then
4850
pool_name=${WORKER_POOLS[$x]//"${CLUSTER_LIST[$i]}-"/}
4951
WORKER_POOL_SOURCE="${ADDRESS_LIST}.ibm_container_vpc_worker_pool.pool[\"${WORKER_POOLS[$x]}\"]"
5052
WORKER_POOL_DESTINATION="${ADDRESS_LIST}.module.cluster[\"${CLUSTER_LIST[$i]}\"].ibm_container_vpc_worker_pool.pool[\"$pool_name\"]"
51-
MOVED_PARAMS+=("$WORKER_POOL_SOURCE, $WORKER_POOL_DESTINATION")
53+
if [ -n "$SOURCE" ] && [ -n "$DESTINATION" ] && [ "${CLUSTER_LIST[$i]}" != 0 ]; then
54+
MOVED_PARAMS+=("$WORKER_POOL_SOURCE, $WORKER_POOL_DESTINATION")
55+
fi
5256
fi
5357
done
5458
done
@@ -65,6 +69,7 @@
6569
- name: Initiate Commands List
6670
set_fact:
6771
commands: []
72+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
6873
- name: Add new JSON Objects to List
6974
set_fact:
7075
commands: "{{ commands +
@@ -75,13 +80,15 @@
7580
loop: "{{ move_list.stdout_lines }}"
7681
loop_control:
7782
index_var: count
83+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
7884
- name: Create complete JSON body
7985
set_fact:
8086
commands: "{{
8187
{ 'commands': commands ,
8288
'operation_name': 'workspace Command',
8389
'description': 'Executing command'}
8490
}}"
91+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
8592
- name: Run Terraform commands
8693
uri:
8794
url: "{{ project_url }}/v1/projects/{{ project_id }}/configs/{{ config_id }}/execute_schematics_commands"
@@ -93,3 +100,4 @@
93100
body_format: json
94101
status_code: [200, 202]
95102
register: result
103+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''

patterns/vsi-extension/scripts/migration-pre-ansible-playbook.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
for x in "${!VSI_LIST[@]}"; do
4040
SOURCE="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${VSI_LIST[$x]}\"]"
4141
DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${subnet_name}-${x}\"]"
42-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
42+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
4343
MOVED_PARAMS+=("$SOURCE, $DESTINATION")
4444
fi
4545
if [ -n "${VSI_LIST[$x]}" ]; then
@@ -51,7 +51,7 @@
5151
if [ -n "$FIP_RESOURCES" ]; then
5252
FIP_SOURCE="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${VSI_LIST[$x]}\"]"
5353
FIP_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${subnet_name}-${x}\"]"
54-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
54+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
5555
MOVED_PARAMS+=("$FIP_SOURCE, $FIP_DESTINATION")
5656
fi
5757
fi
@@ -80,7 +80,7 @@
8080
test="${VOL_LIST[$c]/$str/}"
8181
vol=$(echo "$test" | cut -d"-" -f3-)
8282
VOL_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_volume.volume[\"${subnet_name}-${x}-${vol}\"]"
83-
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ]; then
83+
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
8484
MOVED_PARAMS+=("$VOL_SOURCE, $VOL_DESTINATION")
8585
fi
8686
fi
@@ -104,6 +104,7 @@
104104
- name: Initiate Commands List
105105
set_fact:
106106
commands: []
107+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
107108
- name: Add new JSON Objects to List
108109
set_fact:
109110
commands: "{{ commands +
@@ -114,13 +115,15 @@
114115
loop: "{{ move_list.stdout_lines }}"
115116
loop_control:
116117
index_var: count
118+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
117119
- name: Create complete JSON body
118120
set_fact:
119121
commands: "{{
120122
{ 'commands': commands ,
121123
'operation_name': 'workspace Command',
122124
'description': 'Executing command'}
123125
}}"
126+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
124127
- name: Run Terraform commands
125128
uri:
126129
url: "{{ project_url }}/v1/projects/{{ project_id }}/configs/{{ config_id }}/execute_schematics_commands"
@@ -132,3 +135,4 @@
132135
body_format: json
133136
status_code: [200, 202]
134137
register: result
138+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''

patterns/vsi-quickstart/scripts/migration-pre-ansible-playbook.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
for x in "${!VSI_LIST[@]}"; do
4848
SOURCE="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${VSI_LIST[$x]}\"]"
4949
DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${subnet_name}-${x}\"]"
50-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
50+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
5151
MOVED_PARAMS+=("$SOURCE, $DESTINATION")
5252
fi
5353
if [ -n "${VSI_LIST[$x]}" ]; then
@@ -59,7 +59,7 @@
5959
if [ -n "$FIP_RESOURCES" ]; then
6060
FIP_SOURCE="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${VSI_LIST[$x]}\"]"
6161
FIP_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${subnet_name}-${x}\"]"
62-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
62+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
6363
MOVED_PARAMS+=("$FIP_SOURCE, $FIP_DESTINATION")
6464
fi
6565
fi
@@ -88,7 +88,7 @@
8888
test="${VOL_LIST[$c]/$str/}"
8989
vol=$(echo "$test" | cut -d"-" -f3-)
9090
VOL_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_volume.volume[\"${subnet_name}-${x}-${vol}\"]"
91-
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ]; then
91+
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
9292
MOVED_PARAMS+=("$VOL_SOURCE, $VOL_DESTINATION")
9393
fi
9494
fi
@@ -113,6 +113,7 @@
113113
- name: Initiate Commands List
114114
set_fact:
115115
commands: []
116+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
116117
- name: Add new JSON Objects to List
117118
set_fact:
118119
commands: "{{ commands +
@@ -123,13 +124,15 @@
123124
loop: "{{ move_list.stdout_lines }}"
124125
loop_control:
125126
index_var: count
127+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
126128
- name: Create complete JSON body
127129
set_fact:
128130
commands: "{{
129131
{ 'commands': commands ,
130132
'operation_name': 'workspace Command',
131133
'description': 'Executing command'}
132134
}}"
135+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
133136
- name: Run Terraform commands
134137
uri:
135138
url: "{{ project_url }}/v1/projects/{{ project_id }}/configs/{{ config_id }}/execute_schematics_commands"
@@ -141,3 +144,4 @@
141144
body_format: json
142145
status_code: [200, 202]
143146
register: result
147+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''

patterns/vsi/scripts/migration-pre-ansible-playbook.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
for x in "${!VSI_LIST[@]}"; do
4848
SOURCE="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${VSI_LIST[$x]}\"]"
4949
DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_instance.vsi[\"${subnet_name}-${x}\"]"
50-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
50+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
5151
MOVED_PARAMS+=("$SOURCE, $DESTINATION")
5252
fi
5353
if [ -n "${VSI_LIST[$x]}" ]; then
@@ -59,7 +59,7 @@
5959
if [ -n "$FIP_RESOURCES" ]; then
6060
FIP_SOURCE="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${VSI_LIST[$x]}\"]"
6161
FIP_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_floating_ip.vsi_fip[\"${subnet_name}-${x}\"]"
62-
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ]; then
62+
if [ -n "${VSI_LIST[$x]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
6363
MOVED_PARAMS+=("$FIP_SOURCE, $FIP_DESTINATION")
6464
fi
6565
fi
@@ -88,7 +88,7 @@
8888
test="${VOL_LIST[$c]/$str/}"
8989
vol=$(echo "$test" | cut -d"-" -f3-)
9090
VOL_DESTINATION="${ADDRESS_LIST[$j]}.ibm_is_volume.volume[\"${subnet_name}-${x}-${vol}\"]"
91-
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ]; then
91+
if [ -n "${VOL_LIST[$c]}" ] && [ -n "${subnet_name}" ] && [ "$SOURCE" != "$DESTINATION" ]; then
9292
MOVED_PARAMS+=("$VOL_SOURCE, $VOL_DESTINATION")
9393
fi
9494
fi
@@ -113,6 +113,7 @@
113113
- name: Initiate Commands List
114114
set_fact:
115115
commands: []
116+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
116117
- name: Add new JSON Objects to List
117118
set_fact:
118119
commands: "{{ commands +
@@ -123,13 +124,15 @@
123124
loop: "{{ move_list.stdout_lines }}"
124125
loop_control:
125126
index_var: count
127+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
126128
- name: Create complete JSON body
127129
set_fact:
128130
commands: "{{
129131
{ 'commands': commands ,
130132
'operation_name': 'workspace Command',
131133
'description': 'Executing command'}
132134
}}"
135+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''
133136
- name: Run Terraform commands
134137
uri:
135138
url: "{{ project_url }}/v1/projects/{{ project_id }}/configs/{{ config_id }}/execute_schematics_commands"
@@ -141,3 +144,4 @@
141144
body_format: json
142145
status_code: [200, 202]
143146
register: result
147+
when: move_list is defined and move_list.stdout is defined and move_list.stdout != ''

0 commit comments

Comments
 (0)