Skip to content

Commit 7464b44

Browse files
committed
add worker pools update
1 parent 36aa3ec commit 7464b44

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,40 @@
4646
done
4747
when: version_check.stdout|bool == true
4848
with_items: "{{ cleaned_list }}"
49+
- name: Check for worker pools
50+
ansible.builtin.shell: |
51+
old_worker_pools="$(ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}" | jq -r '.resources[] | select(.instances[].attributes.worker_pool_name != null) | .instances[].index_key' | sort -u)"
52+
if [ -n "$old_worker_pools" ]; then
53+
echo "true"
54+
else
55+
echo "false"
56+
fi
57+
register: worker_pool_check
58+
- name: Update state2 file
59+
ansible.builtin.shell: |
60+
old_worker_pools=($(ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}" | jq -r '.resources[] | select(.instances[].attributes.worker_pool_name != null) | .instances[].index_key' | sort -u))
61+
for pool in "${old_worker_pools[@]}"; do
62+
if [[ $pool == *"{{ item }}"* ]]; then
63+
pool_name=${pool//{{ item }}-/}
64+
ibmcloud schematics workspace state mv --id "{{ workspace_id }}" --source "module.roks_landing_zone.module.landing_zone.ibm_container_vpc_worker_pool.pool[\"$pool\"]" --destination "module.roks_landing_zone.module.landing_zone.module.cluster[\"{{ item }}\"].ibm_container_vpc_worker_pool.pool[\"$pool_name\"]"
65+
sleep 60
66+
while true; do
67+
status=$(ibmcloud schematics workspace get --id "{{ workspace_id }}" -o json | jq -r .status)
68+
echo "$status"
69+
if [[ "$status" == "ACTIVE" ]]; then
70+
echo "Changes done to {{ item }}"
71+
break
72+
elif [[ "$status" == "FAILED" ]]; then
73+
echo "ERROR::Unfortunately, the Schematics workspace is in a FAILED state. Please review the workspace and try running the following command manually:"
74+
echo "ibmcloud schematics workspace state mv --id "{{ workspace_id }}" --source 'module.roks_landing_zone.module.landing_zone.ibm_container_vpc_cluster.cluster[\"{{ item }}\"]' --destination 'module.roks_landing_zone.module.landing_zone.module.cluster[\"{{ item }}\"].ibm_container_vpc_cluster.cluster[0]'"
75+
break
76+
fi
77+
sleep 10
78+
status=""
79+
done
80+
fi
81+
done
82+
with_items: "{{ cleaned_list }}"
83+
when:
84+
- worker_pool_check.stdout|bool == true
85+
- version_check.stdout|bool == true

0 commit comments

Comments
 (0)