|
| 1 | +--- |
| 2 | +- name: "Cordon and drain node" |
| 3 | + hosts: "localhost" |
| 4 | + gather_facts: true |
| 5 | + |
| 6 | + pre_tasks: |
| 7 | + - name: "Check variables" |
| 8 | + ansible.builtin.assert: |
| 9 | + that: |
| 10 | + - nodename is defined and nodename | length > 0 |
| 11 | + - rhosp_instance_name is defined and rhosp_instance_name | length > 0 |
| 12 | + fail_msg: |
| 13 | + - "nodename must be defined with the OpenShift node name." |
| 14 | + - "rhosp_instance_name must be defined with the name of the RHOSP instance." |
| 15 | + |
| 16 | + tasks: |
| 17 | + - name: "Cordon the node" |
| 18 | + ansible.builtin.shell: | |
| 19 | + oc adm cordon {{ nodename }} |
| 20 | + register: oc_adm_cordon_res |
| 21 | + |
| 22 | + - name: "Print cordon result" |
| 23 | + ansible.builtin.debug: |
| 24 | + var: oc_adm_cordon_res |
| 25 | + |
| 26 | + - name: "Drain node" |
| 27 | + ansible.builtin.shell: | |
| 28 | + oc adm drain {{ nodename }} |
| 29 | + register: oc_adm_drain_res |
| 30 | + failed_when: false |
| 31 | + |
| 32 | + - name: "Print drain result" |
| 33 | + ansible.builtin.debug: |
| 34 | + var: oc_adm_drain_res |
| 35 | + |
| 36 | + - name: "Drain force" |
| 37 | + ansible.builtin.shell: | |
| 38 | + oc adm drain {{ nodename }} --delete-emptydir-data --ignore-daemonsets |
| 39 | + when: oc_adm_drain_res.rc != 0 |
| 40 | + register: oc_adm_drain_force_res |
| 41 | + |
| 42 | + - name: "Print drain force result" |
| 43 | + ansible.builtin.debug: |
| 44 | + var: oc_adm_drain_force_res |
| 45 | + when: oc_adm_drain_force_res is defined |
| 46 | + |
| 47 | + - name: "Stop the RHOSP instance" |
| 48 | + openstack.cloud.server_action: |
| 49 | + action: stop |
| 50 | + server: "{{ rhosp_instance_name }}" |
| 51 | + timeout: 200 |
| 52 | + |
| 53 | + - name: "Wait for the VM to stop" |
| 54 | + openstack.cloud.server_info: |
| 55 | + name: "{{ rhosp_instance_name }}" |
| 56 | + register: rhosp_instance_info |
| 57 | + until: "rhosp_instance_info.servers[0].status == 'SHUTOFF'" |
| 58 | + retries: 30 |
| 59 | + delay: 2 |
| 60 | + |
| 61 | + - name: "Start the RHOSP instance" |
| 62 | + openstack.cloud.server_action: |
| 63 | + action: start |
| 64 | + server: "{{ rhosp_instance_name }}" |
| 65 | + timeout: 200 |
| 66 | + |
| 67 | + - name: "Wait for the VM to start" |
| 68 | + openstack.cloud.server_info: |
| 69 | + name: "{{ rhosp_instance_name }}" |
| 70 | + register: rhosp_instance_info |
| 71 | + until: "rhosp_instance_info.servers[0].status == 'ACTIVE'" |
| 72 | + retries: 30 |
| 73 | + delay: 2 |
| 74 | + |
| 75 | + - name: "Print wait result" |
| 76 | + ansible.builtin.debug: |
| 77 | + msg: |
| 78 | + - "rhosp_instance_info: {{ rhosp_instance_info }}" |
| 79 | + - "rhosp_instance_info: {{ rhosp_instance_info | to_json }}" |
| 80 | + |
| 81 | + - name: "Uncordon the node" |
| 82 | + ansible.builtin.shell: | |
| 83 | + oc adm uncordon {{ nodename }} |
| 84 | + register: oc_adm_uncordon_res |
| 85 | + |
| 86 | + - name: "Print uncordon result" |
| 87 | + ansible.builtin.debug: |
| 88 | + var: oc_adm_uncordon_res |
| 89 | +... |
0 commit comments