Debian Codegraph @

ansible_collections/cisco/mso/tests/integration/targets/ndo_template/tasks/main.yml

raw symbols SCIP
1 # Test code for the MSO modules
2 # Copyright: (c) 2024, Akini Ross (@akinross) <[email protected]>
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 - name: Test that we have an ACI MultiSite host, username and password
7 ansible.builtin.fail:
8 msg: "Please define the following variables: mso_hostname, mso_username and mso_password."
9 when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
10
11 # CLEAN ENVIRONMENT
12 - name: Set vars
13 ansible.builtin.set_fact:
14 mso_info: &mso_info
15 host: "{{ mso_hostname }}"
16 username: "{{ mso_username }}"
17 password: "{{ mso_password }}"
18 validate_certs: "{{ mso_validate_certs | default(false) }}"
19 use_ssl: "{{ mso_use_ssl | default(true) }}"
20 use_proxy: "{{ mso_use_proxy | default(true) }}"
21 output_level: '{{ mso_output_level | default("debug") }}'
22
23 # QUERY VERSION
24 - name: Query MSO version
25 cisco.mso.mso_version:
26 <<: *mso_info
27 state: query
28 register: version
29
30 - name: Execute tasks only for MSO version >= 4.3
31 when: version.current.version is version('4.3', '>=')
32 block:
33 - name: Ensure sites exists
34 cisco.mso.mso_site:
35 <<: *mso_info
36 site: "{{ item.site }}"
37 apic_username: "{{ apic_username }}"
38 apic_password: "{{ apic_password }}"
39 apic_site_id: "{{ item.apic_site_id }}"
40 urls:
41 - https://{{ apic_hostname }}
42 state: present
43 loop:
44 - { site: "ansible_test", apic_site_id: 101 }
45 - { site: "ansible_test_2", apic_site_id: 102 }
46
47 - name: Ensure tenants exist
48 cisco.mso.mso_tenant:
49 <<: *mso_info
50 tenant: "{{ item }}"
51 users:
52 - "{{ mso_username }}"
53 sites:
54 - '{{ mso_site | default("ansible_test") }}'
55 - ansible_test_2
56 state: present
57 loop:
58 - ansible_test
59 - ansible_test_2
60
61 - name: Ensure templates do not exist
62 cisco.mso.ndo_template:
63 <<: *mso_info
64 name: "{{ item.name }}"
65 template_type: "{{ item.type }}"
66 state: absent
67 loop:
68 - { name: ansible_tenant_policy, type: tenant }
69 - { name: ansible_tenant_policy_2, type: tenant }
70 - { name: ansible_tenant_policy_changed, type: tenant }
71 - { name: ansible_l3out_policy_template, type: l3out }
72 - { name: ansible_fabric_policy_template, type: fabric_policy }
73 - { name: ansible_fabric_resource_template, type: fabric_resource }
74 - { name: ansible_service_device_template, type: service_device }
75 - { name: ansible_monitoring_tenant_template, type: monitoring_tenant }
76 - { name: ansible_monitoring_access_template, type: monitoring_access }
77
78 # CREATE
79
80 - name: Create a new tenant policy template (check_mode)
81 cisco.mso.ndo_template: &create_tenant_policy_template
82 <<: *mso_info
83 template: ansible_tenant_policy
84 template_type: tenant
85 tenant: ansible_test
86 state: present
87 check_mode: true
88 register: cm_create_new_tenant_policy_template
89
90 - name: Create a new tenant policy template
91 cisco.mso.ndo_template:
92 <<: *create_tenant_policy_template
93 state: present
94 register: nm_create_new_tenant_policy_template
95
96 - name: Create a new tenant policy template again
97 cisco.mso.ndo_template:
98 <<: *create_tenant_policy_template
99 state: present
100 register: nm_create_new_tenant_policy_template_again
101
102 - name: Create a new l3out policy template
103 cisco.mso.ndo_template: &create_l3out_policy_template
104 <<: *mso_info
105 template: ansible_l3out_policy_template
106 template_type: l3out
107 tenant: ansible_test
108 sites:
109 - name: '{{ mso_site | default("ansible_test") }}'
110 state: present
111 register: nm_create_new_l3out_policy_template
112
113 - name: Create a new fabric policy template with 0 sites
114 cisco.mso.ndo_template: &fabric_policy_template
115 <<: *mso_info
116 template: ansible_fabric_policy_template
117 template_type: fabric_policy
118 state: present
119 output_level: debug
120 register: nm_create_new_fabric_policy_template
121
122 - name: Create a new fabric resource template with 1 site
123 cisco.mso.ndo_template: &fabric_resource_template
124 <<: *mso_info
125 template: ansible_fabric_resource_template
126 template_type: fabric_resource
127 sites:
128 - name: '{{ mso_site | default("ansible_test") }}'
129 state: present
130 register: nm_create_new_fabric_resource_template
131
132 - name: Create a new service device template with 2 sites
133 cisco.mso.ndo_template: &service_device_template
134 <<: *mso_info
135 template: ansible_service_device_template
136 template_type: service_device
137 tenant: ansible_test
138 sites:
139 - name: '{{ mso_site | default("ansible_test") }}'
140 - name: ansible_test_2
141 state: present
142 register: nm_create_new_service_device_template
143
144 - name: Create a new monitoring tenant template
145 cisco.mso.ndo_template: &create_monitoring_tenant_template
146 <<: *mso_info
147 template: ansible_monitoring_tenant_template
148 template_type: monitoring_tenant
149 tenant: ansible_test
150 sites:
151 - name: '{{ mso_site | default("ansible_test") }}'
152 state: present
153 register: nm_create_new_monitoring_tenant_template
154
155 - name: Create a new monitoring access template
156 cisco.mso.ndo_template: &create_monitoring_access_template
157 <<: *mso_info
158 template: ansible_monitoring_access_template
159 template_type: monitoring_access
160 sites:
161 - name: '{{ mso_site | default("ansible_test") }}'
162 state: present
163 register: nm_create_new_monitoring_access_template
164
165 - name: Assert tenant policy template was created
166 assert:
167 that:
168 - cm_create_new_tenant_policy_template is changed
169 - cm_create_new_tenant_policy_template.previous == {}
170 - cm_create_new_tenant_policy_template.current.displayName == 'ansible_tenant_policy'
171 - cm_create_new_tenant_policy_template.current.templateType == 'tenantPolicy'
172 - cm_create_new_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
173 - nm_create_new_tenant_policy_template is changed
174 - nm_create_new_tenant_policy_template.previous == {}
175 - nm_create_new_tenant_policy_template.current.displayName == 'ansible_tenant_policy'
176 - nm_create_new_tenant_policy_template.current.templateType == 'tenantPolicy'
177 - nm_create_new_tenant_policy_template.current.templateId is defined
178 - nm_create_new_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
179 - nm_create_new_tenant_policy_template_again is not changed
180 - nm_create_new_tenant_policy_template_again.previous.displayName == 'ansible_tenant_policy'
181 - nm_create_new_tenant_policy_template_again.previous.templateType == 'tenantPolicy'
182 - nm_create_new_tenant_policy_template_again.previous.templateId is defined
183 - nm_create_new_tenant_policy_template_again.previous.tenantPolicyTemplate.template.tenantId is defined
184 - nm_create_new_tenant_policy_template_again.current.displayName == 'ansible_tenant_policy'
185 - nm_create_new_tenant_policy_template_again.current.templateType == 'tenantPolicy'
186 - nm_create_new_tenant_policy_template_again.current.templateId is defined
187 - nm_create_new_tenant_policy_template_again.current.tenantPolicyTemplate.template.tenantId is defined
188 - nm_create_new_l3out_policy_template is changed
189 - nm_create_new_l3out_policy_template.previous == {}
190 - nm_create_new_l3out_policy_template.current.displayName == 'ansible_l3out_policy_template'
191 - nm_create_new_l3out_policy_template.current.templateType == 'l3out'
192 - nm_create_new_l3out_policy_template.current.templateId is defined
193 - nm_create_new_l3out_policy_template.current.l3outTemplate.siteId is defined
194 - nm_create_new_l3out_policy_template.current.l3outTemplate.tenantId is defined
195 - nm_create_new_fabric_policy_template is changed
196 - nm_create_new_fabric_policy_template.previous == {}
197 - nm_create_new_fabric_policy_template.current.displayName == 'ansible_fabric_policy_template'
198 - nm_create_new_fabric_policy_template.current.templateId is defined
199 - nm_create_new_fabric_policy_template.current.fabricPolicyTemplate.template == {}
200 - nm_create_new_fabric_policy_template.proposed.fabricPolicyTemplate.sites == []
201 - nm_create_new_fabric_resource_template is changed
202 - nm_create_new_fabric_resource_template.previous == {}
203 - nm_create_new_fabric_resource_template.current.displayName == 'ansible_fabric_resource_template'
204 - nm_create_new_fabric_resource_template.current.templateId is defined
205 - nm_create_new_fabric_resource_template.current.fabricResourceTemplate.sites | length == 1
206 - nm_create_new_service_device_template is changed
207 - nm_create_new_service_device_template.previous == {}
208 - nm_create_new_service_device_template.current.displayName == 'ansible_service_device_template'
209 - nm_create_new_service_device_template.current.templateId is defined
210 - nm_create_new_service_device_template.current.deviceTemplate.sites | length == 2
211 - nm_create_new_service_device_template.current.deviceTemplate.template.tenantId is defined
212 - nm_create_new_monitoring_tenant_template is changed
213 - nm_create_new_monitoring_tenant_template.previous == {}
214 - nm_create_new_monitoring_tenant_template.current.displayName == 'ansible_monitoring_tenant_template'
215 - nm_create_new_monitoring_tenant_template.current.templateId is defined
216 - nm_create_new_monitoring_tenant_template.current.monitoringTemplate.template.tenant is defined
217 - nm_create_new_monitoring_tenant_template.current.monitoringTemplate.template.mtType == "tenant"
218 - nm_create_new_monitoring_tenant_template.current.monitoringTemplate.sites | length == 1
219 - nm_create_new_monitoring_access_template is changed
220 - nm_create_new_monitoring_access_template.previous == {}
221 - nm_create_new_monitoring_access_template.current.displayName == 'ansible_monitoring_access_template'
222 - nm_create_new_monitoring_access_template.current.templateId is defined
223 - nm_create_new_monitoring_access_template.current.monitoringTemplate.sites | length == 1
224 - nm_create_new_monitoring_access_template.current.monitoringTemplate.template.mtType == "access"
225
226 # UPDATE
227
228 - name: Update a tenant policy template (check_mode)
229 cisco.mso.ndo_template: &update_tenant_policy_template
230 <<: *create_tenant_policy_template
231 template: ansible_tenant_policy_changed
232 template_id: "{{ nm_create_new_tenant_policy_template_again.current.templateId }}"
233 state: present
234 sites:
235 - name: '{{ mso_site | default("ansible_test") }}'
236 - name: ansible_test_2
237 check_mode: true
238 register: cm_update_tenant_policy_template
239
240 - name: Update a tenant policy template
241 cisco.mso.ndo_template:
242 <<: *update_tenant_policy_template
243 state: present
244 register: nm_update_tenant_policy_template
245
246 - name: Update a tenant policy template again
247 cisco.mso.ndo_template:
248 <<: *update_tenant_policy_template
249 state: present
250 register: nm_update_tenant_policy_template_again
251
252 - name: Update a fabric policy template from 0 to 2 sites
253 cisco.mso.ndo_template:
254 <<: *fabric_policy_template
255 sites:
256 - name: '{{ mso_site | default("ansible_test") }}'
257 - name: ansible_test_2
258 state: present
259 register: nm_update_new_fabric_policy_template_0_2_sites
260
261 - name: Update a fabric policy template from 2 to 1 sites ( remove first index )
262 cisco.mso.ndo_template:
263 <<: *fabric_policy_template
264 sites:
265 - name: ansible_test_2
266 state: present
267 register: nm_update_new_fabric_policy_template_2_1_sites_first_index
268
269 - name: Update a fabric policy template from 1 to 2 sites
270 cisco.mso.ndo_template:
271 <<: *fabric_policy_template
272 sites:
273 - name: '{{ mso_site | default("ansible_test") }}'
274 - name: ansible_test_2
275 state: present
276 register: nm_update_new_fabric_policy_template_1_2_sites
277
278 - name: Update a fabric policy template from 2 to 1 sites ( remove second index )
279 cisco.mso.ndo_template:
280 <<: *fabric_policy_template
281 sites:
282 - name: '{{ mso_site | default("ansible_test") }}'
283 state: present
284 register: nm_update_new_fabric_policy_template_2_1_sites_second_index
285
286 - name: Update a fabric policy template without sites (null)
287 cisco.mso.ndo_template:
288 <<: *fabric_policy_template
289 sites: "{{ fakevar | default(omit)}}"
290 state: present
291 register: nm_update_new_fabric_policy_template_1_0_null
292
293 - name: Update a fabric policy template from 1 to 0 sites
294 cisco.mso.ndo_template:
295 <<: *fabric_policy_template
296 sites: []
297 state: present
298 output_level: debug
299 register: nm_update_new_fabric_policy_template_1_0
300
301 - name: Assert tenant policy template was updated
302 assert:
303 that:
304 - cm_update_tenant_policy_template is changed
305 - cm_update_tenant_policy_template.previous.displayName == 'ansible_tenant_policy'
306 - cm_update_tenant_policy_template.previous.templateType == 'tenantPolicy'
307 - cm_update_tenant_policy_template.previous.templateId is defined
308 - cm_update_tenant_policy_template.previous.tenantPolicyTemplate.template.tenantId is defined
309 - cm_update_tenant_policy_template.current.displayName == 'ansible_tenant_policy_changed'
310 - cm_update_tenant_policy_template.current.templateType == 'tenantPolicy'
311 - cm_update_tenant_policy_template.current.templateId is defined
312 - cm_update_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
313 - cm_update_tenant_policy_template.current.tenantPolicyTemplate.sites | length == 2
314 - nm_update_tenant_policy_template is changed
315 - nm_update_tenant_policy_template.previous.displayName == 'ansible_tenant_policy'
316 - nm_update_tenant_policy_template.previous.templateType == 'tenantPolicy'
317 - nm_update_tenant_policy_template.previous.templateId is defined
318 - nm_update_tenant_policy_template.previous.tenantPolicyTemplate.template.tenantId is defined
319 - nm_update_tenant_policy_template.current.displayName == 'ansible_tenant_policy_changed'
320 - nm_update_tenant_policy_template.current.templateType == 'tenantPolicy'
321 - nm_update_tenant_policy_template.current.templateId is defined
322 - nm_update_tenant_policy_template.current.tenantPolicyTemplate.sites | length == 2
323 - nm_update_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
324 - nm_update_tenant_policy_template_again is not changed
325 - nm_update_tenant_policy_template_again.previous.displayName == 'ansible_tenant_policy_changed'
326 - nm_update_tenant_policy_template_again.previous.templateType == 'tenantPolicy'
327 - nm_update_tenant_policy_template_again.previous.templateId is defined
328 - nm_update_tenant_policy_template_again.previous.tenantPolicyTemplate.template.tenantId is defined
329 - nm_update_tenant_policy_template_again.previous.tenantPolicyTemplate.sites | length == 2
330 - nm_update_tenant_policy_template_again.current.displayName == 'ansible_tenant_policy_changed'
331 - nm_update_tenant_policy_template_again.current.templateType == 'tenantPolicy'
332 - nm_update_tenant_policy_template_again.current.templateId is defined
333 - nm_update_tenant_policy_template_again.current.tenantPolicyTemplate.template.tenantId is defined
334 - nm_update_tenant_policy_template_again.current.tenantPolicyTemplate.sites | length == 2
335 - nm_update_new_fabric_policy_template_0_2_sites is changed
336 - nm_update_new_fabric_policy_template_0_2_sites.previous.displayName == 'ansible_fabric_policy_template'
337 - nm_update_new_fabric_policy_template_0_2_sites.previous.fabricPolicyTemplate.sites is not defined
338 - nm_update_new_fabric_policy_template_0_2_sites.current.displayName == 'ansible_fabric_policy_template'
339 - nm_update_new_fabric_policy_template_0_2_sites.current.fabricPolicyTemplate.sites | length == 2
340 - nm_update_new_fabric_policy_template_2_1_sites_first_index is changed
341 - nm_update_new_fabric_policy_template_2_1_sites_first_index.previous.displayName == 'ansible_fabric_policy_template'
342 - nm_update_new_fabric_policy_template_2_1_sites_first_index.previous.fabricPolicyTemplate.sites | length == 2
343 - nm_update_new_fabric_policy_template_2_1_sites_first_index.current.displayName == 'ansible_fabric_policy_template'
344 - nm_update_new_fabric_policy_template_2_1_sites_first_index.current.fabricPolicyTemplate.sites | length == 1
345 - nm_update_new_fabric_policy_template_2_1_sites_first_index.current.fabricPolicyTemplate.sites.0.siteId == nm_update_new_fabric_policy_template_2_1_sites_first_index.previous.fabricPolicyTemplate.sites.1.siteId
346 - nm_update_new_fabric_policy_template_1_2_sites is changed
347 - nm_update_new_fabric_policy_template_1_2_sites.previous.displayName == 'ansible_fabric_policy_template'
348 - nm_update_new_fabric_policy_template_1_2_sites.previous.fabricPolicyTemplate.sites | length == 1
349 - nm_update_new_fabric_policy_template_1_2_sites.current.displayName == 'ansible_fabric_policy_template'
350 - nm_update_new_fabric_policy_template_1_2_sites.current.fabricPolicyTemplate.sites | length == 2
351 - nm_update_new_fabric_policy_template_2_1_sites_second_index is changed
352 - nm_update_new_fabric_policy_template_2_1_sites_second_index.previous.displayName == 'ansible_fabric_policy_template'
353 - nm_update_new_fabric_policy_template_2_1_sites_second_index.previous.fabricPolicyTemplate.sites | length == 2
354 - nm_update_new_fabric_policy_template_2_1_sites_second_index.current.displayName == 'ansible_fabric_policy_template'
355 - nm_update_new_fabric_policy_template_2_1_sites_second_index.current.fabricPolicyTemplate.sites | length == 1
356 - nm_update_new_fabric_policy_template_2_1_sites_second_index.current.fabricPolicyTemplate.sites.0.siteId == nm_update_new_fabric_policy_template_2_1_sites_second_index.previous.fabricPolicyTemplate.sites.1.siteId
357 - nm_update_new_fabric_policy_template_2_1_sites_first_index.current.fabricPolicyTemplate.sites.0.siteId != nm_update_new_fabric_policy_template_2_1_sites_second_index.current.fabricPolicyTemplate.sites.0.siteId
358 - nm_update_new_fabric_policy_template_1_0_null is not changed
359 - nm_update_new_fabric_policy_template_1_0_null.previous.displayName == 'ansible_fabric_policy_template'
360 - nm_update_new_fabric_policy_template_1_0_null.previous.fabricPolicyTemplate.sites | length == 1
361 - nm_update_new_fabric_policy_template_1_0_null.current.displayName == 'ansible_fabric_policy_template'
362 - nm_update_new_fabric_policy_template_1_0_null.current.fabricPolicyTemplate.sites | length == 1
363 - nm_update_new_fabric_policy_template_1_0 is changed
364 - nm_update_new_fabric_policy_template_1_0.previous.displayName == 'ansible_fabric_policy_template'
365 - nm_update_new_fabric_policy_template_1_0.previous.fabricPolicyTemplate.sites | length == 1
366 - nm_update_new_fabric_policy_template_1_0.current.displayName == 'ansible_fabric_policy_template'
367 - nm_update_new_fabric_policy_template_1_0.current.fabricPolicyTemplate.template == {}
368 - nm_update_new_fabric_policy_template_1_0.proposed.fabricPolicyTemplate.sites == []
369
370 # QUERY
371
372 - name: Create another tenant policy template
373 cisco.mso.ndo_template: &create_tenant_policy_template_2
374 <<: *create_tenant_policy_template
375 name: ansible_tenant_policy_2
376 state: present
377 register: nm_create_new_tenant_policy_template
378
379 - name: Query a tenant policy template with template_name
380 cisco.mso.ndo_template:
381 <<: *create_tenant_policy_template_2
382 state: query
383 register: query_new_tenant_policy_template_name
384
385 - name: Query a tenant policy template with template_id
386 cisco.mso.ndo_template:
387 <<: *update_tenant_policy_template
388 template: "{{ fakevar | default(omit)}}"
389 state: query
390 register: query_new_tenant_policy_template_id
391
392 - name: Query all tenant policy templates
393 cisco.mso.ndo_template:
394 <<: *mso_info
395 template_type: tenant
396 state: query
397 register: query_all_tenant
398
399 - name: Query all templates
400 cisco.mso.ndo_template:
401 <<: *mso_info
402 state: query
403 register: query_all
404
405 - name: Assert tenant policy template was queried
406 assert:
407 that:
408 - query_new_tenant_policy_template_name is not changed
409 - query_new_tenant_policy_template_name.current.displayName == 'ansible_tenant_policy_2'
410 - query_new_tenant_policy_template_id is not changed
411 - query_new_tenant_policy_template_id.current.displayName == 'ansible_tenant_policy_changed'
412 - query_all_tenant is not changed
413 - query_all_tenant.current | length >= 2
414 - query_all is not changed
415 - query_all.current | length >= 8
416
417 # Add Schema Template
418 - name: Add an application template
419 cisco.mso.mso_schema_template: &add_application_template
420 <<: *mso_info
421 schema: ansible_test
422 template: application_template_test
423 tenant: ansible_test
424 state: present
425 register: application_template
426
427 - name: Query an application template to get the template_id
428 cisco.mso.mso_schema_template:
429 <<: *mso_info
430 schema: ansible_test
431 template: application_template_test
432 state: query
433 register: query_schema_template
434
435 - name: Query an application template using template_id
436 cisco.mso.ndo_template:
437 <<: *mso_info
438 template_type: application
439 template_id: "{{ query_schema_template.current.templateID }}"
440 state: query
441 register: query_application_template
442
443 - name: Assert query application template using template_id
444 assert:
445 that:
446 - query_schema_template is not changed
447 - query_application_template is not changed
448 - query_schema_template.current.templateID == query_application_template.current.templateId
449 - query_application_template.current.templateType == "application"
450 - query_application_template.current.displayName == "application_template_test"
451
452 # ERRORS
453
454 - name: Error on unknown template
455 cisco.mso.ndo_template:
456 <<: *update_tenant_policy_template
457 template_id: "unknown_id"
458 state: present
459 register: err_unknown_template_id
460 ignore_errors: true
461
462 - name: Error on not allowed template_type change
463 cisco.mso.ndo_template:
464 <<: *create_l3out_policy_template
465 sites: "{{ fakevar | default(omit) }}"
466 template_id: "{{ nm_create_new_l3out_policy_template.current.templateId }}"
467 template_type: tenant
468 state: present
469 register: err_not_allowed_template_type_change
470 ignore_errors: true
471
472 - name: Error on not allowed site change
473 cisco.mso.ndo_template:
474 <<: *create_l3out_policy_template
475 sites:
476 - name: ansible_test_2
477 state: present
478 register: err_not_allowed_site_change
479 ignore_errors: true
480
481 - name: Error on not allowed site change
482 cisco.mso.ndo_template:
483 <<: *create_l3out_policy_template
484 sites:
485 - name: ansible_test
486 - name: ansible_test_2
487 state: present
488 register: err_not_allowed_multiple_sites
489 ignore_errors: true
490
491 - name: Error on not allowed tenant change
492 cisco.mso.ndo_template:
493 <<: *create_l3out_policy_template
494 tenant: ansible_test_2
495 state: present
496 register: err_not_allowed_tenant_change
497 ignore_errors: true
498
499 - name: Error on tenant must be provided
500 cisco.mso.ndo_template:
501 <<: *create_l3out_policy_template
502 name: l3out_policy_template_error
503 tenant: "{{ fakevar | default(omit)}}"
504 state: present
505 register: err_tenant_not_provided
506 ignore_errors: true
507
508 - name: Error on site must be provided
509 cisco.mso.ndo_template:
510 <<: *create_l3out_policy_template
511 name: l3out_policy_template_error
512 sites: "{{ fakevar | default(omit)}}"
513 state: present
514 register: err_site_not_provided
515 ignore_errors: true
516
517 - name: Error on not allowed tenant
518 cisco.mso.ndo_template:
519 <<: *create_monitoring_access_template
520 tenant: ansible_test
521 state: present
522 register: err_not_allowed_tenant
523 ignore_errors: true
524
525 - name: Error on template query without template_type
526 cisco.mso.ndo_template:
527 <<: *update_tenant_policy_template
528 template_id: "{{ fakevar | default(omit)}}"
529 template_type: "{{ fakevar | default(omit)}}"
530 state: query
531 register: err_no_template_type_query
532 ignore_errors: true
533
534 - name: Error on template type application
535 cisco.mso.ndo_template:
536 <<: *mso_info
537 template: application_template
538 template_type: application
539 state: present
540 register: err_no_template_type_application
541 ignore_errors: true
542
543 - name: Assert errors
544 assert:
545 that:
546 - err_unknown_template_id is failed
547 - err_unknown_template_id.msg.startswith("Provided template id 'unknown_id' does not exist. Existing templates:")
548 - err_not_allowed_template_type_change is failed
549 - err_not_allowed_template_type_change.msg == "Template type cannot be changed."
550 - err_not_allowed_site_change is failed
551 - err_not_allowed_site_change.msg == "Site cannot be changed."
552 - err_not_allowed_multiple_sites is failed
553 - err_not_allowed_multiple_sites.msg == "Only one site can be attached to template of type l3out."
554 - err_not_allowed_tenant_change is failed
555 - err_not_allowed_tenant_change.msg == "Tenant cannot be changed."
556 - err_tenant_not_provided is failed
557 - err_tenant_not_provided.msg == "Tenant must be provided for template of type l3out."
558 - err_site_not_provided is failed
559 - err_site_not_provided.msg == "Site must be provided for template of type l3out."
560 - err_not_allowed_tenant is failed
561 - err_not_allowed_tenant.msg == "Tenant cannot be attached to template of type monitoring_access."
562 - err_no_template_type_query is failed
563 - err_no_template_type_query.msg == "Template type must be provided when using template name."
564 - err_no_template_type_application is failed
565 - 'err_no_template_type_application.msg == "The template_type: application is only intended for retrieving the Application template."'
566
567 # DELETE
568
569 - name: Delete a tenant policy template (check_mode)
570 cisco.mso.ndo_template: &delete_tenant_policy_template
571 <<: *update_tenant_policy_template
572 template_id: "{{ fakevar | default(omit)}}"
573 state: absent
574 check_mode: true
575 register: cm_delete_new_tenant_policy_template
576
577 - name: Delete a tenant policy template
578 cisco.mso.ndo_template:
579 <<: *delete_tenant_policy_template
580 register: nm_delete_new_tenant_policy_template
581
582 - name: Delete a tenant policy template again
583 cisco.mso.ndo_template:
584 <<: *delete_tenant_policy_template
585 register: nm_delete_new_tenant_policy_template_again
586
587 - name: Delete a l3out policy template
588 cisco.mso.ndo_template:
589 <<: *create_l3out_policy_template
590 state: absent
591 register: nm_delete_new_l3out_policy_template
592
593 - name: Assert tenant policy template was deleted
594 assert:
595 that:
596 - cm_delete_new_tenant_policy_template is changed
597 - cm_delete_new_tenant_policy_template.previous.displayName == 'ansible_tenant_policy_changed'
598 - cm_delete_new_tenant_policy_template.previous.templateType == 'tenantPolicy'
599 - cm_delete_new_tenant_policy_template.previous.templateId is defined
600 - cm_delete_new_tenant_policy_template.previous.tenantPolicyTemplate.template.tenantId is defined
601 - cm_delete_new_tenant_policy_template.current == {}
602 - nm_delete_new_tenant_policy_template is changed
603 - nm_delete_new_tenant_policy_template.previous.displayName == 'ansible_tenant_policy_changed'
604 - nm_delete_new_tenant_policy_template.previous.templateType == 'tenantPolicy'
605 - nm_delete_new_tenant_policy_template.previous.templateId is defined
606 - nm_delete_new_tenant_policy_template.previous.tenantPolicyTemplate.template.tenantId is defined
607 - nm_delete_new_tenant_policy_template.current == {}
608 - nm_delete_new_tenant_policy_template_again is not changed
609 - nm_delete_new_tenant_policy_template_again.previous == {}
610 - nm_delete_new_tenant_policy_template_again.current == {}
611 - nm_delete_new_l3out_policy_template is changed
612 - nm_delete_new_l3out_policy_template.previous.displayName == 'ansible_l3out_policy_template'
613 - nm_delete_new_l3out_policy_template.previous.templateType == 'l3out'
614 - nm_delete_new_l3out_policy_template.previous.templateId is defined
615 - nm_delete_new_l3out_policy_template.previous.l3outTemplate.siteId is defined
616 - nm_delete_new_l3out_policy_template.previous.l3outTemplate.tenantId is defined
617 - nm_delete_new_l3out_policy_template.current == {}
618
619 # CLEANUP TEMPLATES
620
621 - name: Ensure templates do not exist
622 cisco.mso.ndo_template:
623 <<: *mso_info
624 name: "{{ item.name }}"
625 template_type: "{{ item.type }}"
626 state: absent
627 loop:
628 - { name: ansible_tenant_policy, type: tenant }
629 - { name: ansible_tenant_policy_2, type: tenant }
630 - { name: ansible_tenant_policy_changed, type: tenant }
631 - { name: ansible_l3out_policy_template, type: l3out }
632 - { name: ansible_fabric_policy_template, type: fabric_policy }
633 - { name: ansible_fabric_resource_template, type: fabric_resource }
634 - { name: ansible_service_device_template, type: service_device }
635 - { name: ansible_monitoring_tenant_template, type: monitoring_tenant }
636 - { name: ansible_monitoring_access_template, type: monitoring_access }
637
638 - name: Delete an application template
639 cisco.mso.mso_schema_template:
640 <<: *add_application_template
641 state: absent