|
| 1 | +--- |
| 2 | +- name: Query source SRC_DHCP_ID |
| 3 | + command: > |
| 4 | + {{ neutron_drain_venv }}/bin/openstack |
| 5 | + network agent list --host {{ neutron_drain_host }} |
| 6 | + --agent-type dhcp -f value -c ID |
| 7 | + register: SRC_DHCP_ID |
| 8 | + environment: "{{ openstack_auth_env }}" |
| 9 | + delegate_to: "{{ neutron_drain_host }}" |
| 10 | + vars: |
| 11 | + ansible_host: "{{ hostvars[neutron_drain_host].ansible_host }}" |
| 12 | + |
| 13 | +- name: Set fact containing SRC_DHCP_ID |
| 14 | + set_fact: |
| 15 | + DHCP_SRC_ID: "{{ SRC_DHCP_ID.stdout }}" |
| 16 | + |
| 17 | +- name: Get DHCP agent network IDs |
| 18 | + command: > |
| 19 | + {{ neutron_drain_venv }}/bin/openstack |
| 20 | + network list --agent {{ DHCP_SRC_ID }} -f value -c ID |
| 21 | + register: dhcp_agent_ids |
| 22 | + environment: "{{ openstack_auth_env }}" |
| 23 | + delegate_to: "{{ neutron_drain_host }}" |
| 24 | + vars: |
| 25 | + ansible_host: "{{ hostvars[neutron_drain_host].ansible_host }}" |
| 26 | + |
| 27 | +- name: Set DHCP agent network IDs |
| 28 | + set_fact: |
| 29 | + DHCP_AGENT_IDS: "{{ dhcp_agent_ids.stdout_lines }}" |
| 30 | + |
| 31 | +- name: Remove DHCP agent |
| 32 | + command: > |
| 33 | + {{ neutron_drain_venv }}/bin/openstack |
| 34 | + network agent remove network {{ DHCP_SRC_ID }} {{ item }} --dhcp |
| 35 | + environment: "{{ openstack_auth_env }}" |
| 36 | + delegate_to: "{{ neutron_drain_host }}" |
| 37 | + vars: |
| 38 | + ansible_host: "{{ hostvars[neutron_drain_host].ansible_host }}" |
| 39 | + with_items: |
| 40 | + - "{{ DHCP_AGENT_IDS }}" |
| 41 | + |
| 42 | +- name: Wait for no more dhcp agents to be attached to the host |
| 43 | + block: |
| 44 | + - name: Retry count |
| 45 | + set_fact: |
| 46 | + retry_count: "{{ 0 if retry_count is undefined or retry_count == 'reset' else retry_count | int + 1 }}" |
| 47 | + max_retries: 20 |
| 48 | + |
| 49 | + - name: Verify dhcp agents exist |
| 50 | + command: > |
| 51 | + {{ neutron_drain_venv }}/bin/openstack |
| 52 | + network list --agent {{ DHCP_SRC_ID }} -f value -c ID |
| 53 | + environment: "{{ openstack_auth_env }}" |
| 54 | + delegate_to: "{{ neutron_drain_host }}" |
| 55 | + vars: |
| 56 | + ansible_host: "{{ hostvars[neutron_drain_host].ansible_host }}" |
| 57 | + register: agent_status |
| 58 | + |
| 59 | + - name: Fail if DHCP agent still attached |
| 60 | + fail: |
| 61 | + msg: a DHCP agent is still attached to "{{ L3_SRC_ID }}" |
| 62 | + when: agent_status.stdout | length > 0 |
| 63 | + |
| 64 | + - name: Reset retry count after success |
| 65 | + set_fact: |
| 66 | + retry_count: reset |
| 67 | + rescue: |
| 68 | + - fail: |
| 69 | + msg: | |
| 70 | + Maximum retries waiting for DHCP agents to be detached reached |
| 71 | + when: retry_count | int == max_retries |
| 72 | + |
| 73 | + - name: Reset retry counter if max retries reached (exit loop) |
| 74 | + set_fact: |
| 75 | + retry_count: reset |
| 76 | + failed_when: retry_count == 'reset' |
| 77 | + when: retry_count | int >= max_retries | int |
| 78 | + |
| 79 | +- name: Disable DHCP agent |
| 80 | + command: > |
| 81 | + {{ neutron_drain_venv }}/bin/openstack |
| 82 | + network agent set "{{ DHCP_SRC_ID }}" --disable |
| 83 | + environment: "{{ openstack_auth_env }}" |
| 84 | + delegate_to: "{{ neutron_drain_host }}" |
| 85 | + vars: |
| 86 | + ansible_host: "{{ hostvars[neutron_drain_host].ansible_host }}" |
| 87 | + when: agent_status.stdout | length == 0 |
0 commit comments