|
| 1 | +--- |
| 2 | +- name: Extract short hostname from FQDN |
| 3 | + ansible.builtin.set_fact: |
| 4 | + cifmw_update_hypervisor_short_name: "{{ hypervisor.split('.')[0] }}" |
| 5 | + |
| 6 | +- name: Display current stage |
| 7 | + ansible.builtin.debug: |
| 8 | + msg: "Rebooting {{ cifmw_update_hypervisor_short_name }}" |
| 9 | + |
| 10 | +- name: Define command for nova interaction |
| 11 | + ansible.builtin.set_fact: |
| 12 | + cifmw_update_bash_cmd: >- |
| 13 | + oc rsh -n {{ cifmw_update_namespace }} openstackclient bash -c |
| 14 | +
|
| 15 | +- name: Check active VMs on hypervisor |
| 16 | + environment: |
| 17 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 18 | + PATH: "{{ cifmw_path | default(ansible_env.PATH) }}" |
| 19 | + ansible.builtin.shell: >- |
| 20 | + set -o pipefail; |
| 21 | + {{ cifmw_update_openstack_cmd }} server list --all --host {{ hypervisor }} -f json |
| 22 | + | jq -r -c '.[] | select(.Status | contains("ACTIVE") or contains("PAUSED")) | .ID' |
| 23 | + register: active_vms |
| 24 | + changed_when: false |
| 25 | + |
| 26 | +- name: Evacuate VMs if they are running |
| 27 | + environment: |
| 28 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 29 | + PATH: "{{ cifmw_path | default(ansible_env.PATH) }}" |
| 30 | + ansible.builtin.shell: >- |
| 31 | + {{ cifmw_update_bash_cmd }} ". cloudrc && |
| 32 | + nova host-evacuate-live |
| 33 | + {% if 'ceph' not in storage_backend.stdout %} |
| 34 | + --block-migrate |
| 35 | + {% endif %} |
| 36 | + {{ hypervisor }}" |
| 37 | + when: |
| 38 | + - active_vms.stdout != '' |
| 39 | + - hypervisor_hostnames | length > 1 |
| 40 | + changed_when: true |
| 41 | + |
| 42 | +- name: Wait for compute node to get quiesced |
| 43 | + environment: |
| 44 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 45 | + PATH: "{{ cifmw_path | default(ansible_env.PATH) }}" |
| 46 | + ansible.builtin.shell: >- |
| 47 | + set -o pipefail; |
| 48 | + {{ cifmw_update_openstack_cmd }} server list --all --host {{ hypervisor }} -f json |
| 49 | + | jq -r -c '[.[] | select(.Status | |
| 50 | + contains("ACTIVE") or contains("PAUSED") or contains("MIGRATING"))] |
| 51 | + | length' |
| 52 | + register: compute_node_instances |
| 53 | + until: compute_node_instances.stdout.find("0") > -1 |
| 54 | + retries: 30 |
| 55 | + delay: 5 |
| 56 | + when: |
| 57 | + - active_vms.stdout != '' |
| 58 | + - hypervisor_hostnames | length > 1 |
| 59 | + |
| 60 | +- name: Reboot the hypervisors using CR |
| 61 | + ansible.builtin.include_tasks: reboot_hypervisor_using_cr.yml |
| 62 | + |
| 63 | +- name: Perform sanity checks post-reboot |
| 64 | + ansible.builtin.include_tasks: reboot_hypervisor_sanity_checks.yml |
| 65 | + vars: |
| 66 | + current_hypervisor: "{{ hypervisor }}" |
| 67 | + |
| 68 | +- name: Display current stage |
| 69 | + ansible.builtin.debug: |
| 70 | + msg: "Migrate back {{ item }} to {{ cifmw_update_hypervisor_short_name }}." |
| 71 | + with_items: "{{ active_vms.stdout_lines }}" |
| 72 | + |
| 73 | +- name: Migrate back VMs post-reboot |
| 74 | + environment: |
| 75 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 76 | + PATH: "{{ cifmw_path | default(ansible_env.PATH) }}" |
| 77 | + ansible.builtin.shell: >- |
| 78 | + set -o pipefail; |
| 79 | + {{ cifmw_update_bash_cmd }} ". cloudrc && |
| 80 | + nova live-migration |
| 81 | + {% if 'ceph' not in storage_backend.stdout %} |
| 82 | + --block-migrate |
| 83 | + {% endif %} |
| 84 | + {{ item }} {{ hypervisor }}"; |
| 85 | + {{ cifmw_update_openstack_cmd }} server show {{ item }} -f json | |
| 86 | + jq -r -c '. | .["OS-EXT-SRV-ATTR:host"]' |
| 87 | + register: instance_migration_result |
| 88 | + until: instance_migration_result.stdout.find(hypervisor) > -1 |
| 89 | + retries: 30 |
| 90 | + delay: 5 |
| 91 | + with_items: "{{ active_vms.stdout_lines }}" |
| 92 | + when: |
| 93 | + - active_vms.stdout != '' |
| 94 | + - hypervisor_hostnames | length > 1 |
| 95 | + |
| 96 | +- name: Start VMs post-reboot when only one hypervisor is present |
| 97 | + environment: |
| 98 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 99 | + PATH: "{{ cifmw_path | default(ansible_env.PATH) }}" |
| 100 | + ansible.builtin.shell: >- |
| 101 | + set -o pipefail; |
| 102 | + {{ cifmw_update_openstack_cmd }} server start {{ item }}; |
| 103 | + sleep 5; |
| 104 | + {{ cifmw_update_openstack_cmd }} server show {{ item }} -f json |
| 105 | + | jq -r .status |
| 106 | + register: instance_migration_result |
| 107 | + until: instance_migration_result.stdout == "ACTIVE" |
| 108 | + retries: 30 |
| 109 | + delay: 1 # We already wait 5s in the shell. |
| 110 | + with_items: "{{ active_vms.stdout_lines }}" |
| 111 | + when: |
| 112 | + - active_vms.stdout != '' |
| 113 | + - hypervisor_hostnames | length == 1 |
0 commit comments