|
53 | 53 | - lb_ingress_ip is match(ipv4_regex) |
54 | 54 | block: |
55 | 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 |
| 56 | + ansible.builtin.command: openstack floating ip show {{ lb_ingress_ip }} -f json |
58 | 57 | environment: |
59 | 58 | OS_CLOUD: "{{ user_cloud }}" |
60 | | - register: lb_internal_ip_output |
| 59 | + register: lb_fip_show |
61 | 60 | changed_when: false |
62 | 61 |
|
63 | 62 | - name: Define the internal IP |
64 | 63 | ansible.builtin.set_fact: |
65 | | - lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, lb_internal_ip_output.stdout) }}" |
| 64 | + lb_internal_ip: "{{ internal_lb | ternary(lb_ingress_ip, (lb_fip_show.stdout | from_json).fixed_ip_address) }}" |
66 | 65 |
|
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}' |
| 66 | + - name: List load balancers on OpenStack |
| 67 | + ansible.builtin.command: openstack loadbalancer list -f json |
71 | 68 | environment: |
72 | 69 | OS_CLOUD: "{{ user_cloud }}" |
73 | | - register: svc_lb_type |
| 70 | + register: svc_lb_list |
74 | 71 | changed_when: false |
75 | 72 |
|
| 73 | + - name: Select the LB matching VIP "{{ lb_internal_ip }}" |
| 74 | + ansible.builtin.set_fact: |
| 75 | + svc_lb_matches: "{{ svc_lb_list.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list }}" |
| 76 | + |
76 | 77 | - name: Check the LB exists with the internal IP (VIP address) "{{ lb_internal_ip }}" |
77 | 78 | ansible.builtin.assert: |
78 | | - that: svc_lb_type.stdout | length > 0 |
| 79 | + that: svc_lb_matches | length > 0 |
79 | 80 | fail_msg: Could not find a LB in OSP with the vip_address "{{ lb_internal_ip }}" |
80 | 81 | success_msg: A LB with the vip_address "{{ lb_internal_ip }}" has been found in OSP |
81 | 82 |
|
82 | 83 | - name: Detecte LB Octavia provider |
83 | 84 | ansible.builtin.debug: |
84 | | - msg: "Detected LB Octavia provider: {{ svc_lb_type.stdout }}" |
| 85 | + msg: "Detected LB Octavia provider: {{ svc_lb_matches[0].provider }}" |
85 | 86 |
|
86 | 87 | - name: Get pod names |
87 | 88 | kubernetes.core.k8s_info: |
|
142 | 143 | delay: 15 |
143 | 144 | until: oc_project.resources|length == 0 |
144 | 145 |
|
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 }} |
| 146 | + - name: List load balancers after project deletion |
| 147 | + ansible.builtin.command: openstack loadbalancer list -f json |
149 | 148 | environment: |
150 | 149 | OS_CLOUD: "{{ user_cloud }}" |
151 | | - register: svc_lb |
152 | | - failed_when: svc_lb.rc == 0 |
| 150 | + register: svc_lb_after |
153 | 151 | changed_when: false |
154 | 152 | when: |
155 | 153 | - lb_internal_ip is defined |
156 | 154 | - lb_internal_ip | length > 0 |
157 | 155 |
|
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 |
| 156 | + - name: Check the LB with "{{ lb_ingress_ip }}" ingress IP has been removed from OSP |
| 157 | + ansible.builtin.assert: |
| 158 | + that: |
| 159 | + - (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_ingress_ip) | list | length) == 0 |
| 160 | + - (svc_lb_after.stdout | from_json | selectattr('vip_address', 'defined') | selectattr('vip_address', 'equalto', lb_internal_ip) | list | length) == 0 |
| 161 | + fail_msg: Found a LB in OSP still associated with vip_address "{{ lb_ingress_ip }}" or "{{ lb_internal_ip }}" |
| 162 | + when: |
| 163 | + - lb_internal_ip is defined |
| 164 | + - lb_internal_ip | length > 0 |
| 165 | + |
| 166 | + - name: Check whether the fip "{{ lb_ingress_ip }}" still exists on OSP |
| 167 | + ansible.builtin.command: openstack floating ip show {{ lb_ingress_ip }} -f json |
161 | 168 | environment: |
162 | 169 | OS_CLOUD: "{{ user_cloud }}" |
163 | 170 | register: fip |
164 | | - failed_when: fip.rc == 0 |
| 171 | + failed_when: false |
165 | 172 | changed_when: false |
166 | 173 | when: |
167 | 174 | - lb_internal_ip is defined |
168 | 175 | - lb_internal_ip | length > 0 |
| 176 | + |
| 177 | + - name: Check the fip "{{ lb_ingress_ip }}" has been removed from OSP |
| 178 | + ansible.builtin.assert: |
| 179 | + that: |
| 180 | + - fip.rc != 0 |
| 181 | + fail_msg: FIP "{{ lb_ingress_ip }}" is still present in OSP |
| 182 | + when: |
| 183 | + - lb_internal_ip is defined |
| 184 | + - lb_internal_ip | length > 0 |
0 commit comments