Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_tenant/tasks/httpapi_connection.yml

raw symbols SCIP
1 # Tests HTTTP Connection when a list of host are provided
2
3 - name: Set vars
4 ansible.builtin.set_fact:
5 aci_info: &aci_info
6 host: "{{ aci_hostname }}"
7 username: "{{ aci_username }}"
8 password: "{{ aci_password }}"
9 validate_certs: "{{ aci_validate_certs | default(false) }}"
10 use_ssl: "{{ aci_use_ssl | default(true) }}"
11 use_proxy: "{{ aci_use_proxy | default(true) }}"
12 timeout: 5
13 output_level: debug
14
15 - name: Set vars with the randomly generated list of hosts for the task level operations
16 ansible.builtin.set_fact:
17 last_host_active: "{{ aci_hostname | generate_random_ips(5,5) }}"
18 second_host_active: "{{aci_hostname|generate_random_ips(2,5)}}"
19 no_host_active: "{{aci_hostname|generate_random_ips(0,5)}}"
20
21 - name: Set the actual connection type specified in the inventory (this var is used at the end of this test)
22 ansible.builtin.set_fact:
23 old_connection: "{{ ansible_connection }}"
24
25 - name: Set the connection to httpapi and set session key used in the inventory
26 ansible.builtin.set_fact:
27 ansible_user: "{{ aci_username }}"
28 ansible_password: "{{ aci_password }}"
29 ansible_connection: ansible.netcommon.httpapi
30 ansible_httpapi_session_key: {'admin': "{{ lookup('file', 'pki/admin.key') }}"}
31 ansible_httpapi_validate_certs: "{{ aci_validate_certs | default(false) }}"
32 ansible_httpapi_use_ssl: "{{ aci_use_ssl | default(true) }}"
33 ansible_httpapi_use_proxy: "{{ aci_use_proxy | default(true) }}"
34 ansible_httpapi_port: 443
35 ansible_command_timeout: 5
36
37 - name: Run aci_aaa_user_certificate through the plugin
38 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_aaa_user_certificate/tasks/main.yml
39
40 - name: Add user certificate to be used later in the test
41 cisco.aci.aci_aaa_user_certificate:
42 <<: *aci_info
43 aaa_user: "{{ aci_username }}"
44 name: admin
45 certificate: "{{ lookup('file', 'pki/admin.crt') }}"
46 state: present
47
48 # XML operation, APIC HTTP Error and Connection reset upon changed parameter tests
49 - name: Add a tenant using an XML string (Check xml operations through plugin)
50 cisco.aci.aci_rest:
51 <<: *aci_info
52 path: api/mo/uni.xml
53 method: post
54 content: '<fvTenant name="Sales" descr="Sales departement"/>'
55 register: tenant_xml_plugin
56
57 - name: Add an AP (with non existent tenant)
58 cisco.aci.aci_ap:
59 <<: *aci_info
60 tenant: ansible_test_non_existent
61 ap: ap
62 description: default ap
63 state: present
64 ignore_errors: true
65 register: ap_non_existent_tenant
66
67 - name: Delete Tenant with the wrong username and password (Check that connection resets)
68 cisco.aci.aci_tenant:
69 <<: *aci_info
70 username: wrong_username
71 password: wrong_password
72 tenant: ansible_test
73 state: absent
74 ignore_errors: true
75 register: wrong_credentials
76
77 - name: Set the username to null
78 ansible.builtin.set_fact:
79 ansible_user:
80
81 - name: Delete Tenant with no username in the task or inventory (Check that username is set to the default value)
82 cisco.aci.aci_tenant:
83 host: "{{ aci_hostname }}"
84 password: "{{ aci_password }}"
85 validate_certs: "{{ aci_validate_certs | default(false) }}"
86 use_ssl: "{{ aci_use_ssl | default(true) }}"
87 use_proxy: "{{ aci_use_proxy | default(true) }}"
88 timeout: 5
89 output_level: debug
90 tenant: ansible_test
91 state: absent
92 ignore_errors: true
93 register: no_username
94
95 - name: Revert the username to its original value
96 ansible.builtin.set_fact:
97 ansible_user: "{{ aci_username }}"
98
99 - name: Flatten the registered instances
100 ansible.builtin.set_fact:
101 ap_non_existent_tenant_flattened: "{{ ap_non_existent_tenant.httpapi_logs | flatten }}"
102 wrong_credentials_flattened: "{{ wrong_credentials.httpapi_logs | flatten }}"
103 no_username_flattened: "{{ no_username.httpapi_logs | flatten }}"
104
105 - name: Verify XML operation and HTTP error returned by APIC
106 ansible.builtin.assert:
107 that:
108 - tenant_xml_plugin.status == 200
109 - '"Received response from {{ aci_hostname }} for POST operation with HTTP: 400" in ap_non_existent_tenant_flattened'
110 - '"Re-setting connection due to change in the username" in wrong_credentials_flattened'
111 - '"Re-setting connection due to change in the password" in wrong_credentials_flattened'
112 - '"Connection to {{ aci_hostname }} has failed: HTTP Error 401: Unauthorized" in wrong_credentials_flattened'
113 - '"Establishing login for admin to {{ aci_hostname }}" in no_username_flattened'
114
115 # Simulate HTTP 403 error test
116 - name: Delete Tenant with only password in the task (Check for 403)
117 cisco.aci.aci_tenant:
118 <<: *aci_info
119 host: "{{ last_host_active }}"
120 tenant: ansible_test
121 state: absent
122 register: op17_task_pwd_delete_tenant
123
124 - name: Add Tenant with only password in the task (Check for 403)
125 cisco.aci.aci_tenant:
126 <<: *aci_info
127 host: "{{ last_host_active }}"
128 tenant: ansible_test
129 state: present
130 register: op17_task_pwd_add_tenant
131
132 - name: logout to render the token invalid
133 cisco.aci.aci_rest:
134 <<: *aci_info
135 host: "{{ last_host_active }}"
136 path: /api/aaaLogout.json
137 method: post
138 rsp_subtree_preserve: true
139 content: |
140 {
141 "aaaUser": {
142 "attributes": {
143 "name": "{{ aci_username }}"
144 }
145 }
146 }
147
148 - name: Add an AP with only password in the task (Ensure re-login on the same host)
149 cisco.aci.aci_ap:
150 <<: *aci_info
151 host: "{{ last_host_active }}"
152 tenant: ansible_test
153 ap: ap
154 description: default ap
155 state: present
156 register: op18_task_pwd_add_ap
157
158 - name: Flatten the registered instances
159 ansible.builtin.set_fact:
160 op18_flattened_task_pwd_add_ap: "{{ op18_task_pwd_add_ap.httpapi_logs | flatten }}"
161
162 - name: Verify forbidden error 403
163 ansible.builtin.assert:
164 that:
165 - op17_task_pwd_add_tenant is changed
166 - op18_task_pwd_add_ap is changed
167 - '"Failed to receive response from {{ aci_hostname }} with HTTP Error 403: Forbidden" in op18_flattened_task_pwd_add_ap'
168 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op18_flattened_task_pwd_add_ap'
169 - '"Connection to {{ aci_hostname }} was successful" in op18_flattened_task_pwd_add_ap'
170
171 - name: reset connection to test other scenarios
172 ansible.builtin.meta: reset_connection
173
174 # Precedence test
175 - name: Delete Tenant with password and private key in the task (private_key takes precedence)
176 cisco.aci.aci_tenant:
177 <<: *aci_info
178 private_key: "{{ lookup('file', 'pki/admin.key') }}"
179 tenant: ansible_test
180 state: absent
181 register: op1_task_private_key_delete_tenant
182
183 - name: Add Tenant with password and private key in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
184 cisco.aci.aci_tenant:
185 <<: *aci_info
186 private_key: "{{ lookup('file', 'pki/admin.key') }}"
187 tenant: ansible_test
188 state: present
189 register: op1_task_private_key_add_tenant
190
191 - name: Delete Tenant with password and private key absolute path in the task (private_key takes precedence)
192 cisco.aci.aci_tenant:
193 <<: *aci_info
194 private_key: '{{ role_path }}/pki/admin.key'
195 tenant: ansible_test
196 state: absent
197 register: op1_task_private_key_filename_delete_tenant
198
199 - name: Create Tenant with password and private key relative path in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
200 cisco.aci.aci_tenant:
201 <<: *aci_info
202 private_key: targets/aci_tenant/pki/admin.key
203 tenant: ansible_test
204 state: present
205 register: op1_task_private_key_filename_add_tenant
206
207 - name: Delete Tenant with only password in the task (password in the task takes precedence)
208 cisco.aci.aci_tenant:
209 <<: *aci_info
210 tenant: ansible_test
211 state: absent
212 register: op2_task_pwd_delete_tenant
213
214 - name: Add Tenant with only password in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
215 cisco.aci.aci_tenant:
216 <<: *aci_info
217 tenant: ansible_test
218 state: present
219 register: op2_task_pwd_add_tenant
220
221 - name: Delete Tenant with password and session key in the inventory (session_key takes precedence)
222 cisco.aci.aci_tenant:
223 output_level: debug
224 tenant: ansible_test
225 state: absent
226 register: op3_inventory_session_key_delete_tenant
227
228 - name: Add Tenant with password and session key in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
229 cisco.aci.aci_tenant:
230 output_level: debug
231 tenant: ansible_test
232 state: present
233 register: op3_inventory_session_key_add_tenant
234
235 - name: Remove session key used in the inventory
236 ansible.builtin.set_fact:
237 ansible_httpapi_session_key:
238
239 - name: Delete Tenant with with only password in the inventory (check for authentication with the password in the inventory)
240 cisco.aci.aci_tenant:
241 output_level: debug
242 tenant: ansible_test
243 state: absent
244 register: op4_inventory_pwd_delete_tenant
245
246 - name: Add Tenant with with only password in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
247 cisco.aci.aci_tenant:
248 output_level: debug
249 tenant: ansible_test
250 state: present
251 register: op4_inventory_pwd_add_tenant
252
253 - name: Flatten the registered instances
254 ansible.builtin.set_fact:
255 op1_flattened_task_private_key_delete_tenant: "{{ op1_task_private_key_delete_tenant.httpapi_logs | flatten }}"
256 op1_flattened_task_private_key_add_tenant: "{{ op1_task_private_key_add_tenant.httpapi_logs | flatten }}"
257 op1_flattened_task_private_key_filename_delete_tenant: "{{ op1_task_private_key_filename_delete_tenant.httpapi_logs | flatten }}"
258 op1_flattened_task_private_key_filename_add_tenant: "{{ op1_task_private_key_filename_add_tenant.httpapi_logs | flatten }}"
259 op2_flattened_task_pwd_delete_tenant: "{{ op2_task_pwd_delete_tenant.httpapi_logs | flatten }}"
260 op2_flattened_task_pwd_add_tenant: "{{ op2_task_pwd_add_tenant.httpapi_logs | flatten }}"
261 op3_flattened_inventory_session_key_delete_tenant: "{{ op3_inventory_session_key_delete_tenant.httpapi_logs | flatten }}"
262 op3_flattened_inventory_session_key_add_tenant: "{{ op3_inventory_session_key_add_tenant.httpapi_logs | flatten }}"
263 op4_flattened_inventory_pwd_delete_tenant: "{{ op4_inventory_pwd_delete_tenant.httpapi_logs | flatten }}"
264 op4_flattened_inventory_pwd_add_tenant: "{{ op4_inventory_pwd_add_tenant.httpapi_logs | flatten }}"
265
266 - name: Verify Precedence
267 ansible.builtin.assert:
268 that:
269 - '"Provided Hosts: [''{{ aci_hostname }}'']" in op1_flattened_task_private_key_delete_tenant'
270 - '"Initializing operation on {{ aci_hostname }}" in op1_flattened_task_private_key_delete_tenant'
271 - op1_task_private_key_add_tenant is changed
272 - '"Connection to {{ aci_hostname }} was successful" not in op1_flattened_task_private_key_add_tenant'
273 - op1_task_private_key_filename_delete_tenant is changed
274 - '"Connection to {{ aci_hostname }} was successful" not in op1_flattened_task_private_key_filename_delete_tenant'
275 - op1_task_private_key_filename_add_tenant is changed
276 - '"Connection to {{ aci_hostname }} was successful" not in op1_flattened_task_private_key_filename_add_tenant'
277 - op2_task_pwd_delete_tenant is changed
278 - '"Re-setting connection due to change from private/session key authentication to password authentication" in op2_flattened_task_pwd_delete_tenant'
279 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op2_flattened_task_pwd_delete_tenant'
280 - '"Connection to {{ aci_hostname }} was successful" in op2_flattened_task_pwd_delete_tenant'
281 - op2_task_pwd_add_tenant is changed
282 - '"Connection to {{ aci_hostname }} was successful" not in op2_flattened_task_pwd_add_tenant'
283 - op3_inventory_session_key_delete_tenant is changed
284 - '"Connection to {{ aci_hostname }} was successful" not in op3_flattened_inventory_session_key_delete_tenant'
285 - op3_inventory_session_key_add_tenant is changed
286 - '"Connection to {{ aci_hostname }} was successful" not in op3_flattened_inventory_session_key_add_tenant'
287 - op4_inventory_pwd_delete_tenant is changed
288 - '"Re-setting connection due to change from private/session key authentication to password authentication" in op4_flattened_inventory_pwd_delete_tenant'
289 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op4_flattened_inventory_pwd_delete_tenant'
290 - '"Connection to {{ aci_hostname }} was successful" in op4_flattened_inventory_pwd_delete_tenant'
291 - op4_inventory_pwd_add_tenant is changed
292 - '"Connection to {{ aci_hostname }} was successful" not in op4_flattened_inventory_pwd_add_tenant'
293
294 - name: reset connection to test other scenarios
295 ansible.builtin.meta: reset_connection
296
297 # Switching of hosts test with the password in the task
298 - name: Delete Tenant with only password in the task (Check for successful operation on the last host)
299 cisco.aci.aci_tenant:
300 <<: *aci_info
301 host: "{{ last_host_active }}"
302 tenant: ansible_test
303 state: absent
304 register: op5_task_pwd_delete_tenant
305
306 - name: Add Tenant with only password in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
307 cisco.aci.aci_tenant:
308 <<: *aci_info
309 host: "{{ last_host_active }}"
310 tenant: ansible_test
311 state: present
312 register: op5_task_pwd_add_tenant
313
314 - name: Flatten the registered instances
315 ansible.builtin.set_fact:
316 op5_flattened_task_pwd_delete_tenant: "{{ op5_task_pwd_delete_tenant.httpapi_logs | flatten }}"
317 op5_flattened_task_pwd_add_tenant: "{{ op5_task_pwd_add_tenant.httpapi_logs | flatten }}"
318
319 - name: Verify switching of hosts with the password in the task
320 ansible.builtin.assert:
321 that:
322 - op5_task_pwd_delete_tenant is changed
323 - op5_flattened_task_pwd_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
324 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op5_flattened_task_pwd_delete_tenant'
325 - '"Connection to {{ aci_hostname }} was successful" in op5_flattened_task_pwd_delete_tenant'
326 - op5_task_pwd_add_tenant is changed
327 - '"Connection to {{ aci_hostname }} was successful" not in op5_flattened_task_pwd_add_tenant'
328
329 # Continuing on the connected host test with the password in the task
330 - name: Delete Tenant with only password in the task
331 cisco.aci.aci_tenant:
332 <<: *aci_info
333 host: "{{ second_host_active }}"
334 tenant: ansible_test
335 state: absent
336 register: op6_task_pwd_delete_tenant
337
338 - name: Add Tenant with only password in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
339 cisco.aci.aci_tenant:
340 <<: *aci_info
341 host: "{{ second_host_active }}"
342 tenant: ansible_test
343 state: present
344 register: op6_task_pwd_add_tenant
345
346 - name: Flatten the registered instances
347 ansible.builtin.set_fact:
348 op6_flattened_task_pwd_delete_tenant: "{{ op6_task_pwd_delete_tenant.httpapi_logs | flatten }}"
349 op6_flattened_task_pwd_add_tenant: "{{ op6_task_pwd_add_tenant.httpapi_logs | flatten }}"
350
351 - name: Verify continuation of the operations on the connected host with the password in the task
352 ansible.builtin.assert:
353 that:
354 - op6_task_pwd_delete_tenant is changed
355 - '"Connected host {{ aci_hostname }} found in the provided hosts. Continuing with it." in op6_flattened_task_pwd_delete_tenant'
356 - op6_task_pwd_add_tenant is changed
357 - '"Connection to {{ aci_hostname }} was successful" not in op6_flattened_task_pwd_add_tenant'
358
359 # Change of hosts and no hosts active test with the password in the task
360 - name: Delete Tenant with only password in the task (Check for failed operation)
361 cisco.aci.aci_tenant:
362 <<: *aci_info
363 host: "{{ no_host_active }}"
364 tenant: ansible_test
365 state: absent
366 register: op7_task_pwd_delete_tenant
367 ignore_errors: True
368
369 - name: Add Tenant with only password in the task (Check the reset of the provided list of hosts)
370 cisco.aci.aci_tenant:
371 <<: *aci_info
372 host: "{{ second_host_active }}"
373 tenant: ansible_test
374 state: present
375 register: op7_task_pwd_add_tenant
376
377 - name: Verify failure when no hosts are active
378 ansible.builtin.assert:
379 that:
380 - op7_task_pwd_delete_tenant.error.text | regex_search('No hosts left in the cluster to continue operation! Error on final host [0-9]+(?:\.[0-9]+){3}') is not none
381 - op7_task_pwd_add_tenant is not changed
382
383 # Switching of hosts test with the the inventory password
384 - name: Set list of hosts in the inventory with the last host as active
385 ansible.builtin.set_fact:
386 ansible_host: "{{aci_hostname|generate_random_ips(5,5)}}"
387
388 - name: Delete Tenant with only password in the inventory (Check for successful operation on the last host)
389 cisco.aci.aci_tenant:
390 output_level: debug
391 tenant: ansible_test
392 state: absent
393 register: op8_inventory_pwd_delete_tenant
394
395 - name: Add Tenant with only password in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
396 cisco.aci.aci_tenant:
397 output_level: debug
398 tenant: ansible_test
399 state: present
400 register: op8_inventory_pwd_add_tenant
401
402 - name: Flatten the registered instances
403 ansible.builtin.set_fact:
404 op8_flattened_inventory_pwd_delete_tenant: "{{ op8_inventory_pwd_delete_tenant.httpapi_logs | flatten }}"
405 op8_flattened_inventory_pwd_add_tenant: "{{ op8_inventory_pwd_add_tenant.httpapi_logs | flatten }}"
406
407 - name: Verify switching of hosts with the password in the inventory
408 ansible.builtin.assert:
409 that:
410 - op8_inventory_pwd_delete_tenant is changed
411 - op8_flattened_inventory_pwd_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
412 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op8_flattened_inventory_pwd_delete_tenant'
413 - '"Connection to {{ aci_hostname }} was successful" in op8_flattened_inventory_pwd_delete_tenant'
414 - op8_inventory_pwd_add_tenant is changed
415 - '"Connection to {{ aci_hostname }} was successful" not in op8_flattened_inventory_pwd_add_tenant'
416
417 # Continuing on the connected host test with the inventory password
418 - name: Set list of hosts in the inventory with the second host as active
419 ansible.builtin.set_fact:
420 ansible_host: "{{aci_hostname|generate_random_ips(2,5)}}"
421
422 - name: Delete Tenant with only password in the inventory (Check for execution on the previously connected host)
423 cisco.aci.aci_tenant:
424 output_level: debug
425 tenant: ansible_test
426 state: absent
427 register: op9_inventory_pwd_delete_tenant
428
429 - name: Add Tenant with only password in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
430 cisco.aci.aci_tenant:
431 output_level: debug
432 tenant: ansible_test
433 state: present
434 register: op9_inventory_pwd_add_tenant
435
436 - name: Flatten the registered instances
437 ansible.builtin.set_fact:
438 op9_flattened_inventory_pwd_delete_tenant: "{{ op9_inventory_pwd_delete_tenant.httpapi_logs | flatten }}"
439 op9_flattened_inventory_pwd_add_tenant: "{{ op9_inventory_pwd_add_tenant.httpapi_logs | flatten }}"
440
441 - name: Verify switching of hosts with the password in the inventory
442 ansible.builtin.assert:
443 that:
444 - op9_inventory_pwd_delete_tenant is changed
445 - op9_flattened_inventory_pwd_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
446 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" in op9_flattened_inventory_pwd_delete_tenant'
447 - '"Connection to {{ aci_hostname }} was successful" in op9_flattened_inventory_pwd_delete_tenant'
448 - op9_inventory_pwd_add_tenant is changed
449 - '"Connection to {{ aci_hostname }} was successful" not in op9_flattened_inventory_pwd_add_tenant'
450
451 # Change of hosts and no hosts active test with the inventory password
452 - name: Set list of hosts in the inventory with no active hosts
453 ansible.builtin.set_fact:
454 ansible_host: "{{aci_hostname|generate_random_ips(0,5)}}"
455
456 - name: Delete Tenant with only password in the inventory (Check for failed operation)
457 cisco.aci.aci_tenant:
458 output_level: debug
459 tenant: ansible_test
460 state: absent
461 register: op10_inventory_pwd_delete_tenant
462 ignore_errors: True
463
464 - name: Verify failure when no hosts are active in the inventory
465 ansible.builtin.assert:
466 that:
467 - op10_inventory_pwd_delete_tenant.error.text | regex_search('No hosts left in the cluster to continue operation! Error on final host [0-9]+(?:\.[0-9]+){3}') is not none
468
469 # Switching of hosts test with the private key in the task
470 - name: Delete Tenant with only private key in the task (Check for successful operation on the last host)
471 cisco.aci.aci_tenant:
472 <<: *aci_info
473 host: "{{ last_host_active }}"
474 private_key: "{{ lookup('file', 'pki/admin.key') }}"
475 tenant: ansible_test
476 state: absent
477 register: op11_task_private_key_delete_tenant
478
479 - name: Add Tenant with only private key in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
480 cisco.aci.aci_tenant:
481 <<: *aci_info
482 host: "{{ last_host_active }}"
483 private_key: "{{ lookup('file', 'pki/admin.key') }}"
484 tenant: ansible_test
485 state: present
486 register: op11_task_private_key_add_tenant
487
488 - name: Flatten the registered instances
489 ansible.builtin.set_fact:
490 op11_flattened_task_private_key_delete_tenant: "{{ op11_task_private_key_delete_tenant.httpapi_logs | flatten }}"
491 op11_flattened_task_private_key_add_tenant: "{{ op11_task_private_key_add_tenant.httpapi_logs | flatten }}"
492
493 - name: Verify switching of hosts with the private key in the task
494 ansible.builtin.assert:
495 that:
496 - op11_task_private_key_delete_tenant is changed
497 - op11_flattened_task_private_key_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
498 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" not in op11_flattened_task_private_key_delete_tenant'
499 - '"Connection to {{ aci_hostname }} was successful" not in op11_flattened_task_private_key_delete_tenant'
500 - op11_task_private_key_add_tenant is changed
501 - '"Connection to {{ aci_hostname }} was successful" not in op11_flattened_task_private_key_add_tenant'
502
503 # Continuing on the connected host test with the private key in the task
504 - name: Delete Tenant with only private key in the task (Check for execution on the previously connected host)
505 cisco.aci.aci_tenant:
506 <<: *aci_info
507 host: "{{ second_host_active }}"
508 private_key: "{{ lookup('file', 'pki/admin.key') }}"
509 tenant: ansible_test
510 state: absent
511 register: op12_task_private_key_delete_tenant
512
513 - name: Add Tenant with only private key in the task (Check for execution on the provided aci_hostname with no attempts at re-connection)
514 cisco.aci.aci_tenant:
515 <<: *aci_info
516 host: "{{ second_host_active }}"
517 private_key: "{{ lookup('file', 'pki/admin.key') }}"
518 tenant: ansible_test
519 state: present
520 register: op12_task_private_key_add_tenant
521
522 - name: Flatten the registered instances
523 ansible.builtin.set_fact:
524 op12_flattened_task_private_key_delete_tenant: "{{ op12_task_private_key_delete_tenant.httpapi_logs | flatten }}"
525 op12_flattened_task_private_key_add_tenant: "{{ op12_task_private_key_add_tenant.httpapi_logs | flatten }}"
526
527 - name: Verify continuation of the operations on the connected host with the password in the task
528 ansible.builtin.assert:
529 that:
530 - op12_task_private_key_delete_tenant is changed
531 - '"Connected host {{ aci_hostname }} found in the provided hosts. Continuing with it." in op12_flattened_task_private_key_delete_tenant'
532 - op12_task_private_key_add_tenant is changed
533 - '"Connection to {{ aci_hostname }} was successful" not in op12_flattened_task_private_key_add_tenant'
534
535 # Change of hosts and no hosts active test with the private key in the task
536 - name: Delete Tenant with only private key in the task (Check for failed operation)
537 cisco.aci.aci_tenant:
538 <<: *aci_info
539 host: "{{ no_host_active }}"
540 private_key: "{{ lookup('file', 'pki/admin.key') }}"
541 tenant: ansible_test
542 state: absent
543 register: op13_task_private_key_delete_tenant
544 ignore_errors: True
545
546 - name: Add Tenant with only private key in the task (Check the reset of the provided list of hosts)
547 cisco.aci.aci_tenant:
548 <<: *aci_info
549 host: "{{ second_host_active }}"
550 private_key: "{{ lookup('file', 'pki/admin.key') }}"
551 tenant: ansible_test
552 state: present
553 register: op13_task_private_key_add_tenant
554
555 - name: Verify failure when no hosts are active in the task
556 ansible.builtin.assert:
557 that:
558 - op13_task_private_key_delete_tenant.error.text | regex_search('No hosts left in the cluster to continue operation! Error on final host [0-9]+(?:\.[0-9]+){3}') is not none
559 - op13_task_private_key_add_tenant is not changed
560
561 # Switching of hosts test with the the inventory session key
562 - name: Set list of hosts in the inventory with the last host as active
563 ansible.builtin.set_fact:
564 ansible_host: "{{aci_hostname|generate_random_ips(5,5)}}"
565 ansible_httpapi_session_key: {'admin': "{{ lookup('file', 'pki/admin.key') }}"}
566
567 - name: Delete Tenant with session key in the inventory (Check for successful operation on the last host)
568 cisco.aci.aci_tenant:
569 output_level: debug
570 tenant: ansible_test
571 state: absent
572 register: op14_inventory_session_key_delete_tenant
573
574 - name: Add Tenant with session key in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
575 cisco.aci.aci_tenant:
576 output_level: debug
577 tenant: ansible_test
578 state: present
579 register: op14_inventory_session_key_add_tenant
580
581 - name: Flatten the registered instances
582 ansible.builtin.set_fact:
583 op14_flattened_inventory_session_key_delete_tenant: "{{ op14_inventory_session_key_delete_tenant.httpapi_logs | flatten }}"
584 op14_flattened_inventory_session_key_add_tenant: "{{ op14_inventory_session_key_add_tenant.httpapi_logs | flatten }}"
585
586 - name: Verify switching of hosts with the session key in the inventory
587 ansible.builtin.assert:
588 that:
589 - op14_inventory_session_key_delete_tenant is changed
590 - op14_flattened_inventory_session_key_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
591 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" not in op14_flattened_inventory_session_key_delete_tenant'
592 - '"Connection to {{ aci_hostname }} was successful" not in op14_flattened_inventory_session_key_delete_tenant'
593 - op14_inventory_session_key_add_tenant is changed
594 - '"Connection to {{ aci_hostname }} was successful" not in op14_flattened_inventory_session_key_add_tenant'
595
596 # Continuing on the connected host test with the inventory session key
597 - name: Set list of hosts in the inventory with the second host as active
598 ansible.builtin.set_fact:
599 ansible_host: "{{aci_hostname|generate_random_ips(2,5)}}"
600
601 - name: Delete Tenant with session key in the inventory (Check for execution on the previously connected host)
602 cisco.aci.aci_tenant:
603 output_level: debug
604 tenant: ansible_test
605 state: absent
606 register: op15_inventory_session_key_delete_tenant
607
608 - name: Add Tenant with session key in the inventory (Check for execution on the provided aci_hostname with no attempts at re-connection)
609 cisco.aci.aci_tenant:
610 output_level: debug
611 tenant: ansible_test
612 state: present
613 register: op15_inventory_session_key_add_tenant
614
615 - name: Flatten the registered instances
616 ansible.builtin.set_fact:
617 op15_flattened_inventory_session_key_delete_tenant: "{{ op15_inventory_session_key_delete_tenant.httpapi_logs | flatten }}"
618 op15_flattened_inventory_session_key_add_tenant: "{{ op15_inventory_session_key_add_tenant.httpapi_logs | flatten }}"
619
620 - name: Verify switching of hosts with the session key in the inventory
621 ansible.builtin.assert:
622 that:
623 - op15_inventory_session_key_delete_tenant is changed
624 - op15_flattened_inventory_session_key_delete_tenant | regex_search('Switching host from [0-9]+(?:\.[0-9]+){3} to {{ aci_hostname }}') is not none
625 - '"Establishing login for {{ aci_username }} to {{ aci_hostname }}" not in op15_flattened_inventory_session_key_delete_tenant'
626 - '"Connection to {{ aci_hostname }} was successful" not in op15_flattened_inventory_session_key_delete_tenant'
627 - op15_inventory_session_key_add_tenant is changed
628 - '"Connection to {{ aci_hostname }} was successful" not in op15_flattened_inventory_session_key_add_tenant'
629
630 # Change of hosts and no hosts active test with the inventory session key
631 - name: Set list of hosts in the inventory with no active hosts
632 ansible.builtin.set_fact:
633 ansible_host: "{{aci_hostname|generate_random_ips(0,5)}}"
634
635 - name: Delete Tenant with session key in the inventory (Check for failed operation)
636 cisco.aci.aci_tenant:
637 output_level: debug
638 tenant: ansible_test
639 state: absent
640 register: op16_inventory_session_key_delete_tenant
641 ignore_errors: True
642
643 - name: Verify failure when no hosts are active in the inventory
644 ansible.builtin.assert:
645 that:
646 - op16_inventory_session_key_delete_tenant.error.text | regex_search('No hosts left in the cluster to continue operation! Error on final host [0-9]+(?:\.[0-9]+){3}') is not none
647
648 # Clean up Environment
649 - name: Delete a tenant using an XML string
650 cisco.aci.aci_rest:
651 <<: *aci_info
652 path: api/mo/uni/tn-[Sales].xml
653 method: delete
654 content: '<fvTenant name="Sales" descr="Sales departement"/>'
655
656 - name: Remove user certificate
657 cisco.aci.aci_aaa_user_certificate:
658 <<: *aci_info
659 aaa_user: "{{ aci_username }}"
660 name: admin
661 certificate: "{{ lookup('file', 'pki/admin.crt') }}"
662 state: absent
663
664 - name: Delete Tenant
665 cisco.aci.aci_tenant:
666 <<: *aci_info
667 port: 443
668 tenant: ansible_test
669 state: absent
670
671 - name: Cleanup facts to continue operation using the inventory file
672 ansible.builtin.set_fact:
673 ansible_host: "{{ aci_hostname }}"
674 ansible_connection: "{{ old_connection }}"
675 ansible_httpapi_session_key: