Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_aep/tasks/main.yml

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2018, Dag Wieers (@dagwieers) <[email protected]>
3 # Copyright: (c) 2024, Samita Bhattacharjee (@samiib) <[email protected]>
4
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 - name: Test that we have an ACI APIC host, ACI username and ACI password
8 ansible.builtin.fail:
9 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
10 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
11
12 - name: Verify Cloud and Non-Cloud Sites in use.
13 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
14
15 - name: Execute tasks only for non-cloud sites
16 when: query_cloud.current == [] # This condition will execute only non-cloud sites
17 block: # block specifies execution of tasks within, based on conditions
18 # CLEAN ENVIRONMENT
19 - name: Remove AEP
20 cisco.aci.aci_aep: &aep_absent
21 host: '{{ aci_hostname }}'
22 username: '{{ aci_username }}'
23 password: '{{ aci_password }}'
24 validate_certs: '{{ aci_validate_certs | default(false) }}'
25 use_ssl: '{{ aci_use_ssl | default(true) }}'
26 use_proxy: '{{ aci_use_proxy | default(true) }}'
27 output_level: '{{ aci_output_level | default("info") }}'
28 aep: '{{ item }}'
29 state: absent
30 loop:
31 - ansible_test
32 - ansible_test2
33 - ansible_test3
34
35 # ADD AEP
36 - name: Add AEP (check_mode)
37 cisco.aci.aci_aep: &aep_present
38 host: '{{ aci_hostname }}'
39 username: '{{ aci_username }}'
40 password: '{{ aci_password }}'
41 validate_certs: '{{ aci_validate_certs | default(false) }}'
42 use_ssl: '{{ aci_use_ssl | default(true) }}'
43 use_proxy: '{{ aci_use_proxy | default(true) }}'
44 output_level: '{{ aci_output_level | default("info") }}'
45 aep: ansible_test
46 infra_vlan: true
47 state: present
48 check_mode: true
49 register: cm_add_aep
50
51 - name: Add AEP (normal mode)
52 cisco.aci.aci_aep: *aep_present
53 register: nm_add_aep
54
55 - name: Add another AEP (normal mode)
56 cisco.aci.aci_aep:
57 <<: *aep_present
58 aep: ansible_test2
59 infra_vlan: true
60 register: nm_add_aep2
61
62 - name: Add another AEP (normal mode)
63 cisco.aci.aci_aep:
64 <<: *aep_present
65 aep: ansible_test3
66 infra_vlan: false
67 register: nm_add_aep3
68
69 - name: Verify add_aep
70 ansible.builtin.assert:
71 that:
72 - cm_add_aep is changed
73 - nm_add_aep is changed
74 - nm_add_aep.current.0.infraAttEntityP.attributes.annotation == 'orchestrator:ansible'
75 - nm_add_aep2 is changed
76 - nm_add_aep3 is changed
77 - nm_add_aep.previous == nm_add_aep.previous == cm_add_aep.current == []
78 - nm_add_aep.current[0].infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
79 - nm_add_aep.current[0].infraAttEntityP.attributes.name == 'ansible_test'
80 - cm_add_aep.proposed.infraAttEntityP.attributes.name == nm_add_aep.proposed.infraAttEntityP.attributes.name == cm_add_aep.sent.infraAttEntityP.attributes.name == nm_add_aep.sent.infraAttEntityP.attributes.name == 'ansible_test'
81 - nm_add_aep2.current[0].infraAttEntityP.children[0].infraProvAcc.attributes.name == 'provacc'
82 - nm_add_aep3.current[0].infraAttEntityP | length == 1
83
84 - name: Change AEP infra(normal mode)
85 cisco.aci.aci_aep:
86 <<: *aep_present
87 aep: ansible_test2
88 infra_vlan: false
89 register: nm_add_aep_true_to_false
90
91 - name: Change AEP infra again(normal mode)
92 cisco.aci.aci_aep:
93 <<: *aep_present
94 aep: ansible_test2
95 infra_vlan: false
96 register: nm_add_aep_true_to_false_again
97
98 - name: Add AEP again (check_mode)
99 cisco.aci.aci_aep:
100 <<: *aep_present
101 check_mode: true
102 register: cm_add_aep_again
103
104 - name: Add AEP again (normal mode)
105 cisco.aci.aci_aep:
106 <<: *aep_present
107 register: nm_add_aep_again
108
109 - name: Verify add_aep_again
110 ansible.builtin.assert:
111 that:
112 - cm_add_aep_again is not changed
113 - nm_add_aep_again is not changed
114 - nm_add_aep_again.previous[0].infraAttEntityP.attributes.dn == nm_add_aep_again.previous[0].infraAttEntityP.attributes.dn == cm_add_aep_again.current[0].infraAttEntityP.attributes.dn == nm_add_aep_again.current[0].infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
115 - nm_add_aep_again.previous[0].infraAttEntityP.attributes.name == nm_add_aep_again.previous[0].infraAttEntityP.attributes.name == cm_add_aep_again.current[0].infraAttEntityP.attributes.name == nm_add_aep_again.current[0].infraAttEntityP.attributes.name == 'ansible_test'
116 - cm_add_aep_again.proposed.infraAttEntityP.attributes.name == nm_add_aep_again.proposed.infraAttEntityP.attributes.name == 'ansible_test'
117 - cm_add_aep_again.sent == nm_add_aep_again.sent == {}
118 - nm_add_aep_true_to_false.current[0].infraAttEntityP | length == 1
119 - nm_add_aep_true_to_false_again.current[0].infraAttEntityP | length == 1
120
121 # CHANGE AEP
122 - name: Change description of AEP (check_mode)
123 cisco.aci.aci_aep:
124 <<: *aep_present
125 description: Ansible test AEP
126 check_mode: true
127 register: cm_add_aep_descr
128
129 - name: Change description of AEP (normal mode)
130 cisco.aci.aci_aep:
131 <<: *aep_present
132 description: Ansible test AEP
133 register: nm_add_aep_descr
134
135 - name: Verify add_aep_descr
136 ansible.builtin.assert:
137 that:
138 - cm_add_aep_descr is changed
139 - nm_add_aep_descr is changed
140 - cm_add_aep_descr.proposed.infraAttEntityP.attributes.descr == nm_add_aep_descr.proposed.infraAttEntityP.attributes.descr == 'Ansible test AEP'
141 - cm_add_aep_descr.proposed.infraAttEntityP.attributes.name == nm_add_aep_descr.proposed.infraAttEntityP.attributes.name == 'ansible_test'
142 - cm_add_aep_descr.sent.infraAttEntityP.attributes.descr == nm_add_aep_descr.sent.infraAttEntityP.attributes.descr == 'Ansible test AEP'
143 - cm_add_aep_descr.previous.0.infraAttEntityP.attributes.dn == nm_add_aep_descr.previous.0.infraAttEntityP.attributes.dn == cm_add_aep_descr.current.0.infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
144 - cm_add_aep_descr.previous.0.infraAttEntityP.attributes.name == nm_add_aep_descr.previous.0.infraAttEntityP.attributes.name == cm_add_aep_descr.current.0.infraAttEntityP.attributes.name == 'ansible_test'
145 - nm_add_aep_descr.current.0.infraAttEntityP.attributes.descr == 'Ansible test AEP'
146 - nm_add_aep_descr.current.0.infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
147 - nm_add_aep_descr.current.0.infraAttEntityP.attributes.name == 'ansible_test'
148
149 - name: Change description of AEP again (check_mode)
150 cisco.aci.aci_aep:
151 <<: *aep_present
152 description: Ansible test AEP
153 check_mode: true
154 register: cm_add_aep_descr_again
155
156 - name: Change description of AEP again (normal mode)
157 cisco.aci.aci_aep:
158 <<: *aep_present
159 description: Ansible test AEP
160 register: nm_add_aep_descr_again
161
162 - name: Verify add_aep_descr_again
163 ansible.builtin.assert:
164 that:
165 - cm_add_aep_descr_again is not changed
166 - nm_add_aep_descr_again is not changed
167 - cm_add_aep_descr_again.proposed.infraAttEntityP.attributes.descr == nm_add_aep_descr_again.proposed.infraAttEntityP.attributes.descr == 'Ansible test AEP'
168 - cm_add_aep_descr_again.proposed.infraAttEntityP.attributes.name == nm_add_aep_descr_again.proposed.infraAttEntityP.attributes.name == 'ansible_test'
169 - cm_add_aep_descr_again.sent == nm_add_aep_descr_again.sent == {}
170 - cm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.descr == nm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.descr == cm_add_aep_descr_again.current[0].infraAttEntityP.attributes.descr == nm_add_aep_descr_again.current[0].infraAttEntityP.attributes.descr == 'Ansible test AEP'
171 - cm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.dn == nm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.dn == cm_add_aep_descr_again.current[0].infraAttEntityP.attributes.dn == nm_add_aep_descr_again.current[0].infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
172 - cm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.name == nm_add_aep_descr_again.previous[0].infraAttEntityP.attributes.name == cm_add_aep_descr_again.current[0].infraAttEntityP.attributes.name == nm_add_aep_descr_again.current[0].infraAttEntityP.attributes.name == 'ansible_test'
173
174
175 # ADD AEP AGAIN
176 - name: Add AEP again with no description (check_mode)
177 cisco.aci.aci_aep: *aep_present
178 check_mode: true
179 register: cm_add_aep_again_no_descr
180
181 - name: Add AEP again with no description (normal mode)
182 cisco.aci.aci_aep: *aep_present
183 register: nm_add_aep_again_no_descr
184
185 - name: Verify add_aep_again_no_descr
186 ansible.builtin.assert:
187 that:
188 - cm_add_aep_again_no_descr is not changed
189 - nm_add_aep_again_no_descr is not changed
190 - cm_add_aep_again_no_descr.proposed.infraAttEntityP.attributes.name == nm_add_aep_again_no_descr.proposed.infraAttEntityP.attributes.name == 'ansible_test'
191 - cm_add_aep_again_no_descr.sent == nm_add_aep_again_no_descr.sent == {}
192 - cm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.descr == nm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.descr == cm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.descr == nm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.descr == 'Ansible test AEP'
193 - cm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.dn == nm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.dn == cm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.dn == nm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
194 - cm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.name == nm_add_aep_again_no_descr.previous[0].infraAttEntityP.attributes.name == cm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.name == nm_add_aep_again_no_descr.current[0].infraAttEntityP.attributes.name == 'ansible_test'
195
196 # TEST NO VERIFICATION
197 - name: Create aep with no verification (check mode)
198 cisco.aci.aci_aep: &aci_aep_no_verify
199 <<: *aep_present
200 aep: anstest-no-verify
201 description: Ansible Test
202 no_verification: true
203 check_mode: true
204 register: aep_present_no_verify_cm
205
206 - name: Create aep with no verification
207 cisco.aci.aci_aep:
208 <<: *aci_aep_no_verify
209 register: aep_present_no_verify
210
211 - name: Create aep with no verification again
212 cisco.aci.aci_aep:
213 <<: *aci_aep_no_verify
214 register: aep_present_no_verify_again
215
216 - name: Update aep with no verification
217 cisco.aci.aci_aep:
218 <<: *aci_aep_no_verify
219 description: Ansible Test No Verify
220 register: update_aep_present_no_verify
221
222 - name: Delete aep with no verification
223 cisco.aci.aci_aep:
224 <<: *aci_aep_no_verify
225 state: absent
226 register: delete_aep_present_no_verify
227
228 - name: Delete aep with no verification again
229 cisco.aci.aci_aep:
230 <<: *aci_aep_no_verify
231 state: absent
232 register: delete_aep_present_no_verify_again
233
234 - name: No verification asserts
235 ansible.builtin.assert:
236 that:
237 - aep_present_no_verify_cm is changed
238 - aep_present_no_verify_cm.current_verified == false
239 - aep_present_no_verify_cm.current.0 == aep_present_no_verify_cm.proposed
240 - aep_present_no_verify is changed
241 - aep_present_no_verify.current_verified == false
242 - aep_present_no_verify.current.0 == aep_present_no_verify.proposed
243 - aep_present_no_verify.previous == []
244 - aep_present_no_verify_again is not changed
245 - aep_present_no_verify_again.current_verified == true
246 - aep_present_no_verify_again.current.0.infraAttEntityP.attributes.name == "anstest-no-verify"
247 - aep_present_no_verify_again.current.0.infraAttEntityP.attributes.descr == "Ansible Test"
248 - aep_present_no_verify_again.previous.0.infraAttEntityP.attributes.name == "anstest-no-verify"
249 - aep_present_no_verify_again.previous.0.infraAttEntityP.attributes.descr == "Ansible Test"
250 - update_aep_present_no_verify is changed
251 - update_aep_present_no_verify.current_verified == false
252 - update_aep_present_no_verify.current.0 == update_aep_present_no_verify.proposed
253 - update_aep_present_no_verify.previous.0.infraAttEntityP.attributes.name == "anstest-no-verify"
254 - update_aep_present_no_verify.previous.0.infraAttEntityP.attributes.descr == "Ansible Test"
255 - delete_aep_present_no_verify is changed
256 - delete_aep_present_no_verify.current_verified == false
257 - delete_aep_present_no_verify.current.0 == delete_aep_present_no_verify.proposed
258 - delete_aep_present_no_verify.previous.0.infraAttEntityP.attributes.name == "anstest-no-verify"
259 - delete_aep_present_no_verify.previous.0.infraAttEntityP.attributes.descr == "Ansible Test No Verify"
260 - delete_aep_present_no_verify_again is not changed
261 - delete_aep_present_no_verify_again.current_verified == true
262 - delete_aep_present_no_verify_again.current == []
263 - delete_aep_present_no_verify_again.previous == []
264 - delete_aep_present_no_verify_again.proposed == {}
265
266 # QUERY ALL AEPS
267 - name: Query all AEPs (check_mode)
268 cisco.aci.aci_aep: &aep_query
269 host: '{{ aci_hostname }}'
270 username: '{{ aci_username }}'
271 password: '{{ aci_password }}'
272 validate_certs: '{{ aci_validate_certs | default(false) }}'
273 use_ssl: '{{ aci_use_ssl | default(true) }}'
274 use_proxy: '{{ aci_use_proxy | default(true) }}'
275 output_level: '{{ aci_output_level | default("info") }}'
276 state: query
277 check_mode: true
278 register: cm_query_all_aeps
279
280 - name: Query all AEPs (normal mode)
281 cisco.aci.aci_aep: *aep_query
282 register: nm_query_all_aeps
283
284 - name: Verify query_all_aeps
285 ansible.builtin.assert:
286 that:
287 - cm_query_all_aeps is not changed
288 - nm_query_all_aeps is not changed
289 - cm_query_all_aeps == nm_query_all_aeps
290 - nm_query_all_aeps.current|length >= 1
291
292
293 # QUERY A AEP
294 - name: Query our AEP
295 cisco.aci.aci_aep:
296 <<: *aep_query
297 aep: ansible_test
298 check_mode: true
299 register: cm_query_aep
300
301 - name: Query our AEP
302 cisco.aci.aci_aep:
303 <<: *aep_query
304 aep: ansible_test
305 register: nm_query_aep
306
307 - name: Verify query_aep
308 ansible.builtin.assert:
309 that:
310 - cm_query_aep is not changed
311 - nm_query_aep is not changed
312 - cm_query_aep == nm_query_aep
313 - nm_query_aep.current.0.infraAttEntityP.attributes.descr == "Ansible test AEP"
314 - nm_query_aep.current.0.infraAttEntityP.attributes.dn == "uni/infra/attentp-ansible_test"
315 - nm_query_aep.current.0.infraAttEntityP.attributes.name == "ansible_test"
316
317
318 # REMOVE AEP
319 - name: Remove AEP (check_mode)
320 cisco.aci.aci_aep:
321 <<: *aep_absent
322 aep: ansible_test
323 check_mode: true
324 register: cm_remove_aep
325
326 - name: Remove AEP (normal mode)
327 cisco.aci.aci_aep:
328 <<: *aep_absent
329 aep: ansible_test
330 register: nm_remove_aep
331
332 - name: Verify remove_aep
333 ansible.builtin.assert:
334 that:
335 - cm_remove_aep is changed
336 - nm_remove_aep is changed
337 - cm_remove_aep.proposed == nm_remove_aep.proposed == {}
338 - cm_remove_aep.sent == nm_remove_aep.sent == {}
339 - cm_remove_aep.previous[0].infraAttEntityP.attributes.name == nm_remove_aep.previous[0].infraAttEntityP.attributes.name == cm_remove_aep.current[0].infraAttEntityP.attributes.name == 'ansible_test'
340 - cm_remove_aep.previous[0].infraAttEntityP.attributes.descr == nm_remove_aep.previous[0].infraAttEntityP.attributes.descr == cm_remove_aep.current[0].infraAttEntityP.attributes.descr == 'Ansible test AEP'
341 - cm_remove_aep.previous[0].infraAttEntityP.attributes.dn == nm_remove_aep.previous[0].infraAttEntityP.attributes.dn == cm_remove_aep.current[0].infraAttEntityP.attributes.dn == 'uni/infra/attentp-ansible_test'
342 - nm_remove_aep.current == []
343
344 - name: Remove AEP again (check_mode)
345 cisco.aci.aci_aep:
346 <<: *aep_absent
347 aep: ansible_test
348 check_mode: true
349 register: cm_remove_aep_again
350
351 - name: Remove AEP again (normal mode)
352 cisco.aci.aci_aep:
353 <<: *aep_absent
354 aep: ansible_test
355 register: nm_remove_aep_again
356
357 - name: Verify remove_aep_again
358 ansible.builtin.assert:
359 that:
360 - cm_remove_aep_again is not changed
361 - nm_remove_aep_again is not changed
362 - cm_remove_aep_again.proposed == nm_remove_aep_again.proposed == {}
363 - cm_remove_aep_again.sent == nm_remove_aep_again.sent == {}
364 - cm_remove_aep_again.previous == nm_remove_aep_again.previous == cm_remove_aep_again.current == nm_remove_aep_again.current == []
365
366
367 # QUERY NON-EXISTING AEP
368 - name: Query non-existing AEP (check_mode)
369 cisco.aci.aci_aep:
370 <<: *aep_query
371 aep: ansible_test
372 check_mode: true
373 register: cm_query_non_aep
374
375 - name: Query non-existing AEP (normal mode)
376 cisco.aci.aci_aep:
377 <<: *aep_query
378 aep: ansible_test
379 register: nm_query_non_aep
380
381 - name: Verify query_non_aep
382 ansible.builtin.assert:
383 that:
384 - cm_query_non_aep is not changed
385 - nm_query_non_aep is not changed
386 - cm_query_non_aep == nm_query_non_aep
387 - cm_query_non_aep.current == nm_query_non_aep.current == []
388
389
390 # PROVOKE ERRORS
391 - name: Error when required parameter is missing
392 cisco.aci.aci_aep:
393 host: '{{ aci_hostname }}'
394 username: '{{ aci_username }}'
395 password: '{{ aci_password }}'
396 validate_certs: '{{ aci_validate_certs | default(false) }}'
397 use_ssl: '{{ aci_use_ssl | default(true) }}'
398 use_proxy: '{{ aci_use_proxy | default(true) }}'
399 output_level: '{{ aci_output_level | default("info") }}'
400 state: present
401 ignore_errors: true
402 register: error_on_missing_required_param
403
404 - name: Verify error_on_missing_required_param
405 ansible.builtin.assert:
406 that:
407 - error_on_missing_required_param is failed
408 - 'error_on_missing_required_param.msg == "state is present but all of the following are missing: aep"'