|
| 1 | +--- |
| 2 | +- name: Extract short hostname from FQDN |
| 3 | + ansible.builtin.set_fact: |
| 4 | + cifmw_update_hypervisor_short_name: "{{ hypervisor.split('.')[0] }}" |
| 5 | + |
| 6 | +- debug: |
| 7 | + msg: "Rebooting {{ cifmw_update_hypervisor_short_name }}" |
| 8 | + |
| 9 | +- name: Check active VMs on hypervisor |
| 10 | + ansible.builtin.shell: >- |
| 11 | + {{ cifmw_update_openstack_cmd }} server list --all --host {{ hypervisor }} -f json |
| 12 | + | jq -r -c '.[] | select(.Status | contains("ACTIVE") or contains("PAUSED")) | .ID' |
| 13 | + register: active_vms |
| 14 | + changed_when: false |
| 15 | + |
| 16 | +- name: Evacuate VMs if they are running |
| 17 | + ansible.builtin.shell: >- |
| 18 | + {{ cifmw_update_bash_cmd }} ". cloudrc && |
| 19 | + nova host-evacuate-live |
| 20 | + {% if 'ceph' not in storage_backend.stdout %} |
| 21 | + --block-migrate |
| 22 | + {% endif %} |
| 23 | + {{ hypervisor }}" |
| 24 | + when: active_vms.stdout != '' |
| 25 | + changed_when: true |
| 26 | + |
| 27 | +- name: Wait for compute node to get quiesced |
| 28 | + ansible.builtin.shell: >- |
| 29 | + {{ cifmw_update_openstack_cmd }} server list --all --host {{ hypervisor }} -f json |
| 30 | + | jq -r -c '[.[] | select(.Status | |
| 31 | + contains("ACTIVE") or contains("PAUSED") or contains("MIGRATING"))] |
| 32 | + | length' |
| 33 | + register: compute_node_instances |
| 34 | + until: compute_node_instances.stdout.find("0") > -1 |
| 35 | + retries: 30 |
| 36 | + delay: 5 |
| 37 | + when: |
| 38 | + - active_vms.stdout != '' |
| 39 | + |
| 40 | +- name: Reboot the hypervisor |
| 41 | + ansible.builtin.include_tasks: reboot_hypervisor_using_cr.yml |
| 42 | + |
| 43 | +- name: Perform sanity checks post-reboot |
| 44 | + ansible.builtin.include_tasks: reboot_hypervisor_sanity_checks.yml |
| 45 | + vars: |
| 46 | + current_hypervisor: "{{ hypervisor }}" |
| 47 | + |
| 48 | +- debug: |
| 49 | + msg: "Migrate back {{ item }} to {{ cifmw_update_hypervisor_short_name }}." |
| 50 | + with_items: "{{ active_vms.stdout_lines }}" |
| 51 | + |
| 52 | +- name: Migrate back VMs post-reboot |
| 53 | + ansible.builtin.shell: >- |
| 54 | + set -o pipefail; |
| 55 | + {{ cifmw_update_bash_cmd }} ". cloudrc && |
| 56 | + nova live-migration |
| 57 | + {% if 'ceph' not in storage_backend.stdout %} |
| 58 | + --block-migrate |
| 59 | + {% endif %} |
| 60 | + {{ item }} {{ hypervisor }}"; |
| 61 | + {{ cifmw_update_openstack_cmd }} server show {{ item }} -f json | |
| 62 | + jq -r -c '. | .["OS-EXT-SRV-ATTR:host"]' |
| 63 | + register: instance_migration_result |
| 64 | + until: instance_migration_result.stdout.find(hypervisor) > -1 |
| 65 | + retries: 30 |
| 66 | + delay: 5 |
| 67 | + with_items: "{{ active_vms.stdout_lines }}" |
| 68 | + when: |
| 69 | + - active_vms.stdout != '' |
0 commit comments