|  | 
| 8 | 8 |       ansible.builtin.shell: | 
| 9 | 9 |         cmd: ibmcloud schematics workspace get --id "{{ workspace_id }}" -o json | jq -r .template_data[0].id | 
| 10 | 10 |       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 | 
| 14 | 15 |     - name: Get Cluster names | 
| 15 | 16 |       ansible.builtin.shell: | 
| 16 | 17 |         cmd: ibmcloud schematics state pull --id "{{ workspace_id }}" --template "{{ template_id.stdout }}" | jq -r '.outputs.cluster_names.value' | tr -d '[]," ' | 
| 17 | 18 |       register: cluster_names | 
|  | 19 | +    - set_fact: | 
|  | 20 | +        cleaned_list: "{{ cluster_names.stdout_lines | reject('equalto', '') | list }}" | 
| 18 | 21 |     - name: Print the Cluster names | 
| 19 | 22 |       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 }}" | 
0 commit comments