Skip to content

Commit f885770

Browse files
committed
update ansible script
1 parent fe88798 commit f885770

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

migration/schematics_migration_v4.4.0_to_v5.0.0.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
### NOTE: Make sure the clusters are openshift clusters as the SLZ has been updated to only support ROKS cluster creation using module. If there are IKS cluster being tracked in the state file please use the terraform cli to manually move the ROKS clusters. Please refer to the https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone/blob/extend-output/migration/update-version.md on steps to run terraform cli commands.
44

5-
65
if [ -z "$1" ]; then
76
echo "ERROR::Please ensure you provide correct Workspace ID as the parameter and try again"
87
else
@@ -46,7 +45,7 @@ else
4645
break
4746
elif [[ "$status" == "FAILED" ]]; then
4847
echo "ERROR::Unfortunately, the Schematics workspace is in a FAILED state. Please review the workspace and try running the following command manually:"
49-
echo "ibmcloud schematics workspace state mv --id ""$WS_ID"" --source 'module.landing_zone.ibm_container_vpc_worker_pool.pool[\"$pool\"]' --destination 'mmodule.landing_zone.module.cluster[\"$cluster\"].ibm_container_vpc_worker_pool.pool[\"$pool_name\"]'"
48+
echo "ibmcloud schematics workspace state mv --id "$WS_ID" --source 'module.landing_zone.ibm_container_vpc_worker_pool.pool[\"$pool\"]' --destination 'module.landing_zone.module.cluster[\"$cluster\"].ibm_container_vpc_worker_pool.pool[\"$pool_name\"]'"
5049
break
5150
fi
5251
sleep 10

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,45 @@
88
ansible.builtin.shell:
99
cmd: ibmcloud schematics workspace get --id "{{ workspace_id }}" -o json | jq -r .template_data[0].id
1010
register: template_id
11-
- name: Print the Template ID
12-
ansible.builtin.debug:
13-
var: template_id
11+
- name: Get State
12+
ansible.builtin.shell:
13+
cmd: ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}"
14+
register: state
1415
- name: Get Cluster names
1516
ansible.builtin.shell:
1617
cmd: ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}" | jq -r '.outputs.cluster_names.value' | tr -d '[]," '
1718
register: cluster_names
19+
- set_fact:
20+
cleaned_list: "{{ cluster_names.stdout_lines | reject('equalto', '') | list }}"
1821
- name: Print the Cluster names
1922
ansible.builtin.debug:
20-
var: cluster_names
21-
- name: Print the updated list
22-
ansible.builtin.debug:
23-
var: cluster_names.stdout_lines
24-
- name: Create the Jinja2 based template
25-
template: src=./moved.j2 dest=../moved.tf
23+
var: cleaned_list
24+
- name: Check for old version of landing zone
25+
ansible.builtin.shell: |
26+
cluster="$(ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}" | jq -r '.resources[] | select((.module == "module.roks_landing_zone.module.landing_zone") and (.name == "cluster"))')"
27+
if [ -n "$cluster" ]; then
28+
echo "true"
29+
else
30+
echo "false"
31+
fi
32+
register: version_check
33+
- name: Update state file
34+
ansible.builtin.shell: |
35+
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]"
36+
sleep 60
37+
while true; do
38+
status=$(ibmcloud schematics workspace get --id "{{ workspace_id }}" -o json | jq -r .status)
39+
echo "$status"
40+
if [[ "$status" == "ACTIVE" ]]; then
41+
echo "Changes done to {{ item }}"
42+
break
43+
elif [[ "$status" == "FAILED" ]]; then
44+
echo "ERROR::Unfortunately, the Schematics workspace is in a FAILED state. Please review the workspace and try running the following command manually:"
45+
echo "ibmcloud schematics workspace state mv --id "{{ workspace_id }}" --source 'module.landing_zone.ibm_container_vpc_cluster.cluster[\"{{ item }}\"]' --destination 'module.landing_zone.module.cluster[\"{{ item }}\"].ibm_container_vpc_cluster.cluster[0]'"
46+
break
47+
fi
48+
sleep 10
49+
status=""
50+
done
51+
when: version_check.stdout|bool == true
52+
with_items: "{{ cleaned_list }}"

patterns/roks/scripts/moved.j2

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)