|
52 | 52 | - not internal_lb |
53 | 53 | - lb_ingress_ip is match(ipv4_regex) |
54 | 54 | block: |
55 | | - - name: Get the LB internal IP on openstack when the lb is using a FIP |
56 | | - ansible.builtin.shell: | |
57 | | - openstack floating ip show {{ lb_ingress_ip }} -c fixed_ip_address -f value |
| 55 | + # NOTE: `openstack floating ip show … -f <any>` is broken on the |
| 56 | + # shiftstackclient OSC ("Invalid formatter provided"). Use list+filter. |
| 57 | + - name: Get the LB FIP details on openstack when the lb is using a FIP |
| 58 | + ansible.builtin.command: openstack floating ip list --floating-ip-address {{ lb_ingress_ip }} -f json |
58 | 59 | environment: |
59 | 60 | OS_CLOUD: "{{ user_cloud }}" |
60 | | - register: lb_internal_ip_output |
| 61 | + register: lb_fip_list |
61 | 62 | changed_when: false |
62 | 63 |
|
| 64 | + - name: Check the FIP "{{ lb_ingress_ip }}" exists on OpenStack |
| 65 | + ansible.builtin.assert: |
| 66 | + that: |
| 67 | + - (lb_fip_list.stdout | from_json | length) > 0 |
| 68 | + fail_msg: Could not find floating IP "{{ lb_ingress_ip }}" in OSP |
| 69 | + |
63 | 70 | - name: Define the internal IP |
64 | 71 | ansible.builtin.set_fact: |
65 | | - lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, lb_internal_ip_output.stdout) }}" |
| 72 | + lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, (lb_fip_list.stdout | from_json | first)['Fixed IP Address']) }}" |
66 | 73 |
|
67 | | - - name: Get the Octavia provider type for the LB |
68 | | - ansible.builtin.shell: | |
69 | | - set -o pipefail |
70 | | - openstack loadbalancer list -c vip_address -c provider -f value | grep {{ lb_internal_ip }} | awk '{print $2}' |
| 74 | + - name: List load balancers on OpenStack |
| 75 | + ansible.builtin.command: openstack loadbalancer list -f json |
71 | 76 | environment: |
72 | 77 | OS_CLOUD: "{{ user_cloud }}" |
73 | | - register: svc_lb_type |
| 78 | + register: svc_lb_list |
74 | 79 | changed_when: false |
75 | 80 |
|
| 81 | + - name: Select the LB matching VIP "{{ lb_internal_ip }}" |
| 82 | + ansible.builtin.set_fact: |
| 83 | + svc_lb_matches: "{{ svc_lb_list.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list }}" |
| 84 | + |
76 | 85 | - name: Check the LB exists with the internal IP (VIP address) "{{ lb_internal_ip }}" |
77 | 86 | ansible.builtin.assert: |
78 | | - that: svc_lb_type.stdout | length > 0 |
| 87 | + that: svc_lb_matches | length > 0 |
79 | 88 | fail_msg: Could not find a LB in OSP with the vip_address "{{ lb_internal_ip }}" |
80 | 89 | success_msg: A LB with the vip_address "{{ lb_internal_ip }}" has been found in OSP |
81 | 90 |
|
82 | 91 | - name: Detecte LB Octavia provider |
83 | 92 | ansible.builtin.debug: |
84 | | - msg: "Detected LB Octavia provider: {{ svc_lb_type.stdout }}" |
| 93 | + msg: "Detected LB Octavia provider: {{ svc_lb_matches[0].provider }}" |
85 | 94 |
|
86 | 95 | - name: Get pod names |
87 | 96 | kubernetes.core.k8s_info: |
|
142 | 151 | delay: 15 |
143 | 152 | until: oc_project.resources|length == 0 |
144 | 153 |
|
145 | | - - name: Check the LB with "{{ lb_ingress_ip }}" ingress IP has been removed from OSP |
146 | | - ansible.builtin.shell: | |
147 | | - set -o pipefail |
148 | | - openstack loadbalancer list -f value | grep {{ lb_ingress_ip }} |
| 154 | + - name: List load balancers after project deletion |
| 155 | + ansible.builtin.command: openstack loadbalancer list -f json |
149 | 156 | environment: |
150 | 157 | OS_CLOUD: "{{ user_cloud }}" |
151 | | - register: svc_lb |
152 | | - failed_when: svc_lb.rc == 0 |
| 158 | + register: svc_lb_after |
153 | 159 | changed_when: false |
154 | 160 | when: |
155 | 161 | - lb_internal_ip is defined |
156 | 162 | - lb_internal_ip | length > 0 |
157 | 163 |
|
158 | | - - name: Check the fip "{{ lb_ingress_ip }}" has been removed from OSP |
159 | | - ansible.builtin.shell: | |
160 | | - openstack floating ip show {{ lb_ingress_ip }} -f value |
| 164 | + - name: Check the LB with "{{ lb_ingress_ip }}" ingress IP has been removed from OSP |
| 165 | + ansible.builtin.assert: |
| 166 | + that: |
| 167 | + - (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_ingress_ip) | list | length) == 0 |
| 168 | + - (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list | length) == 0 |
| 169 | + fail_msg: Found a LB in OSP still associated with vip_address "{{ lb_ingress_ip }}" or "{{ lb_internal_ip }}" |
| 170 | + when: |
| 171 | + - lb_internal_ip is defined |
| 172 | + - lb_internal_ip | length > 0 |
| 173 | + |
| 174 | + # Prefer list over show: floating ip show -f * fails on shiftstackclient OSC. |
| 175 | + - name: Check whether the fip "{{ lb_ingress_ip }}" still exists on OSP |
| 176 | + ansible.builtin.command: openstack floating ip list --floating-ip-address {{ lb_ingress_ip }} -f json |
161 | 177 | environment: |
162 | 178 | OS_CLOUD: "{{ user_cloud }}" |
163 | | - register: fip |
164 | | - failed_when: fip.rc == 0 |
| 179 | + register: fip_list |
165 | 180 | changed_when: false |
166 | 181 | when: |
167 | 182 | - lb_internal_ip is defined |
168 | 183 | - lb_internal_ip | length > 0 |
| 184 | + |
| 185 | + - name: Check the fip "{{ lb_ingress_ip }}" has been removed from OSP |
| 186 | + ansible.builtin.assert: |
| 187 | + that: |
| 188 | + - (fip_list.stdout | from_json | length) == 0 |
| 189 | + fail_msg: FIP "{{ lb_ingress_ip }}" is still present in OSP |
| 190 | + when: |
| 191 | + - lb_internal_ip is defined |
| 192 | + - lb_internal_ip | length > 0 |
0 commit comments