Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2022, Sabari Jaganathan (@sajagana)
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 APIC host, ACI username and ACI password
7 ansible.builtin.fail:
8 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
9 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
10
11 # SET VARS
12 - name: Set vars
13 ansible.builtin.set_fact:
14 aci_info: &aci_info
15 host: '{{ aci_hostname }}'
16 username: '{{ aci_username }}'
17 password: '{{ aci_password }}'
18 validate_certs: '{{ aci_validate_certs | default(false) }}'
19 use_ssl: '{{ aci_use_ssl | default(true) }}'
20 use_proxy: '{{ aci_use_proxy | default(true) }}'
21 output_level: '{{ aci_output_level | default("info") }}'
22
23 - name: Query system information
24 cisco.aci.aci_system:
25 <<: *aci_info
26 id: 1
27 state: query
28 register: version
29
30 - name: Verify Cloud and Non-Cloud Sites in use.
31 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
32
33 - name: Ensure tenant - ansible_test does not exists before testing
34 cisco.aci.aci_tenant: &tenant_absent
35 <<: *aci_info
36 output_level: debug
37 tenant: ansible_test
38 state: absent
39
40 - name: Execute tasks only for ACI v5+ and non-cloud sites
41 when:
42 - version.current.0.topSystem.attributes.version is version('5', '>=')
43 - query_cloud.current == [] # This condition will execute only non-cloud sites
44 block: # block specifies execution of tasks within, based on conditions
45 # Setup part
46 - name: Ensure ansible_test - tenant exists
47 cisco.aci.aci_tenant: &tenant_present
48 <<: *tenant_absent
49 state: present
50
51 - name: Ensure ap - application profile exists
52 cisco.aci.aci_ap: &anstest_ap_present
53 <<: *tenant_present
54 ap: anstest_ap
55 state: present
56
57 - name: Ensure anstest_ap_1 - application profile exists
58 cisco.aci.aci_ap: &anstest_ap_1_present
59 <<: *tenant_present
60 ap: anstest_ap_1
61 state: present
62
63 # Test Part
64 - name: Ensure web_esg_0 - endpoint security group exists with check mode
65 cisco.aci.aci_esg: &cm_web_esg_0_present
66 <<: *anstest_ap_present
67 esg: web_esg_0
68 vrf: default
69 state: present
70 check_mode: true
71 register: cm_web_esg_0_present
72
73 - name: Assertions check for add web_esg_0 with check mode
74 ansible.builtin.assert:
75 that:
76 - cm_web_esg_0_present is changed
77 - cm_web_esg_0_present.current | length == 0
78 - cm_web_esg_0_present.previous | length == 0
79
80 - name: Ensure web_esg_0 - endpoint security group exists with normal mode
81 cisco.aci.aci_esg: &nm_web_esg_0_present
82 <<: *cm_web_esg_0_present
83 register: nm_web_esg_0_present
84
85 - name: Assertions check for add web_esg_0 with normal mode
86 ansible.builtin.assert:
87 that:
88 - nm_web_esg_0_present is changed
89 - nm_web_esg_0_present.current | length == 1
90 - nm_web_esg_0_present.previous | length == 0
91 - nm_web_esg_0_present.current.0.fvESg.attributes.name == 'web_esg_0'
92 - nm_web_esg_0_present.current.0.fvESg.attributes.prio == 'unspecified'
93 - nm_web_esg_0_present.current.0.fvESg.attributes.prefGrMemb == 'exclude'
94 - nm_web_esg_0_present.current.0.fvESg.attributes.pcEnfPref == 'unenforced'
95 - nm_web_esg_0_present.current.0.fvESg.attributes.annotation == 'orchestrator:ansible'
96 - nm_web_esg_0_present.current.0.fvESg.children[0].fvRsScope.attributes.tnFvCtxName == 'default'
97
98 - name: Assertions check for add web_esg_0 with normal mode (v5.2+)
99 ansible.builtin.assert:
100 that:
101 - nm_web_esg_0_present.current.0.fvESg.attributes.shutdown == 'no'
102 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
103
104 - name: Ensure web_esg_0 - endpoint security group exists with normal mode - idempotency works
105 cisco.aci.aci_esg:
106 <<: *nm_web_esg_0_present
107 register: idempotency_web_esg_0_present
108
109 - name: Idempotency assertions check for add web_esg_0 with normal mode
110 ansible.builtin.assert:
111 that:
112 - idempotency_web_esg_0_present is not changed
113 - idempotency_web_esg_0_present.current | length == 1
114 - idempotency_web_esg_0_present.previous | length == 1
115 - idempotency_web_esg_0_present.current.0.fvESg.attributes.name == 'web_esg_0'
116
117 - name: Ensure web_esg_0 - endpoint security group exists under ap(anstest_ap_1_present)
118 cisco.aci.aci_esg:
119 <<: *anstest_ap_1_present
120 esg: web_esg_0
121 vrf: default
122 state: present
123 register: ap_1_web_esg_0_present
124
125 - name: Assertions check for add web_esg_0 under ap(anstest_ap_1_present)
126 ansible.builtin.assert:
127 that:
128 - ap_1_web_esg_0_present is changed
129 - ap_1_web_esg_0_present.current | length == 1
130 - ap_1_web_esg_0_present.previous | length == 0
131 - ap_1_web_esg_0_present.current.0.fvESg.attributes.name == 'web_esg_0'
132 - ap_1_web_esg_0_present.current.0.fvESg.attributes.dn == "uni/tn-ansible_test/ap-anstest_ap_1/esg-web_esg_0"
133
134 - name: Ensure web_esg_1 - endpoint security group exists with admin_state(false -> no) - 'Admin Up' on the UI side
135 cisco.aci.aci_esg:
136 <<: *anstest_ap_present
137 esg: web_esg_1
138 vrf: default
139 admin_state: false
140 state: present
141 register: web_esg_1_present
142 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
143
144 - name: Assertions check for add web_esg_1
145 ansible.builtin.assert:
146 that:
147 - web_esg_1_present is changed
148 - web_esg_1_present.current | length == 1
149 - web_esg_1_present.previous | length == 0
150 - web_esg_1_present.current.0.fvESg.attributes.name == 'web_esg_1'
151 - web_esg_1_present.current.0.fvESg.children[0].fvRsScope.attributes.tnFvCtxName == 'default'
152 - web_esg_1_present.current.0.fvESg.attributes.shutdown == 'no'
153 - web_esg_1_present.sent.fvESg.attributes.shutdown == 'no'
154 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
155
156 - name: Ensure web_esg_2 - endpoint security group exists with admin_state(true -> yes) - 'Admin Shut' on the UI side
157 cisco.aci.aci_esg:
158 <<: *anstest_ap_present
159 esg: web_esg_2
160 admin_state: true
161 vrf: default
162 state: present
163 register: web_esg_2_present
164 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
165
166 - name: Assertions check for add web_esg_2
167 ansible.builtin.assert:
168 that:
169 - web_esg_2_present is changed
170 - web_esg_2_present.current | length == 1
171 - web_esg_2_present.previous | length == 0
172 - web_esg_2_present.current.0.fvESg.attributes.name == 'web_esg_2'
173 - web_esg_2_present.current.0.fvESg.attributes.shutdown == 'yes'
174 - web_esg_2_present.current.0.fvESg.children[0].fvRsScope.attributes.tnFvCtxName == 'default'
175 - web_esg_2_present.sent.fvESg.attributes.shutdown == 'yes'
176 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
177
178 - name: Query an ESG
179 cisco.aci.aci_esg:
180 <<: *anstest_ap_present
181 esg: web_esg_0
182 state: query
183 register: query_web_esg_0
184
185 - name: Assertions check for query an ESG(web_esg_0) under ap(anstest_ap)
186 ansible.builtin.assert:
187 that:
188 - query_web_esg_0 is not changed
189 - query_web_esg_0.current | length == 1
190 - query_web_esg_0.current.0.fvESg.attributes.name == 'web_esg_0'
191 - query_web_esg_0.current.0.fvESg.attributes.dn == "uni/tn-ansible_test/ap-anstest_ap/esg-web_esg_0"
192
193 - name: Assertions check for query an ESG(web_esg_0) under ap(anstest_ap) (v5.2+)
194 ansible.builtin.assert:
195 that:
196 - query_web_esg_0.current.0.fvESg.attributes.shutdown == 'no'
197 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
198
199 - name: Query all ESGs
200 cisco.aci.aci_esg:
201 <<: *aci_info
202 state: query
203 register: query_all_esg
204
205 - name: Assertions check for query all ESGs
206 ansible.builtin.assert:
207 that:
208 - query_all_esg is not changed
209 - query_all_esg.current | length >= 2 # Count of ESGs added in the above tasks
210 when: version.current.0.topSystem.attributes.version is version('5.2', '<')
211
212 - name: Assertions check for query all ESGs
213 ansible.builtin.assert:
214 that:
215 - query_all_esg is not changed
216 - query_all_esg.current | length >= 4 # Count of ESGs added in the above tasks
217 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
218
219 - name: Query all ESGs with a Specific Name
220 cisco.aci.aci_esg:
221 <<: *aci_info
222 esg: web_esg_0
223 state: query
224 register: query_all_esg_with_name
225
226 - name: Assertions check for query all ESGs with a Specific Name
227 ansible.builtin.assert:
228 that:
229 - query_all_esg_with_name is not changed
230 - query_all_esg_with_name.current | length >= 2
231
232 - name: Query all ESGs of an App Profile
233 cisco.aci.aci_esg:
234 <<: *aci_info
235 ap: anstest_ap
236 state: query
237 register: query_all_ap_esg
238
239 - name: Assertions check for query all ESGs of an App Profile (<v5.2)
240 ansible.builtin.assert:
241 that:
242 - query_all_ap_esg is not changed
243 - query_all_ap_esg.current.0.fvAp.attributes.name == 'anstest_ap'
244 - query_all_ap_esg.current.0.fvAp.children | length == 1
245 when: version.current.0.topSystem.attributes.version is version('5.2', '<')
246
247 - name: Assertions check for query all ESGs of an App Profile (>=v5.2)
248 ansible.builtin.assert:
249 that:
250 - query_all_ap_esg is not changed
251 - query_all_ap_esg.current.0.fvAp.attributes.name == 'anstest_ap'
252 - query_all_ap_esg.current.0.fvAp.children | length == 3
253 when: version.current.0.topSystem.attributes.version is version('5.2', '>=')
254
255 - name: Remove an ESG with check mode
256 cisco.aci.aci_esg: &cm_web_esg_0_absent
257 <<: *anstest_ap_present
258 esg: web_esg_0
259 state: absent
260 register: cm_web_esg_0_absent
261 check_mode: true
262
263 - name: Assertions check for remove an ESG with check mode
264 ansible.builtin.assert:
265 that:
266 - cm_web_esg_0_absent is changed
267 - cm_web_esg_0_absent.current | length == 1
268 - cm_web_esg_0_absent.previous | length == 1
269 - cm_web_esg_0_absent.current.0.fvESg.attributes.name == 'web_esg_0'
270 - cm_web_esg_0_absent.previous.0.fvESg.attributes.name == 'web_esg_0'
271
272 - name: Remove an ESG with normal mode
273 cisco.aci.aci_esg: &nm_web_esg_0_absent
274 <<: *cm_web_esg_0_absent
275 register: nm_web_esg_0_absent
276
277 - name: Assertions check for remove an ESG with normal mode
278 ansible.builtin.assert:
279 that:
280 - nm_web_esg_0_absent is changed
281 - nm_web_esg_0_absent.current == []
282 - nm_web_esg_0_absent.previous | length == 1
283 - nm_web_esg_0_absent.previous.0.fvESg.attributes.name == 'web_esg_0'
284
285 - name: Remove an ESG with normal mode - idempotency works
286 cisco.aci.aci_esg:
287 <<: *nm_web_esg_0_absent
288 register: idempotency_web_esg_0_absent
289
290 - name: Idempotency assertions check for remove an ESG with normal mode
291 ansible.builtin.assert:
292 that:
293 - idempotency_web_esg_0_absent is not changed
294 - idempotency_web_esg_0_absent.current == []
295 - idempotency_web_esg_0_absent.previous == []
296
297 # Cleanup part
298 - name: Remove ap - application profile
299 cisco.aci.aci_ap:
300 <<: *anstest_ap_present
301 state: absent
302
303 - name: Remove ansible_test - tenant
304 cisco.aci.aci_tenant:
305 <<: *tenant_present
306 state: absent