Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2021, Tim Cragg(@timcragg)
3 # Copyright: (c) 2023, Akini Ross(@akinross)
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: 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: debug
22
23 # CLEAN ENVIRONMENT
24 - name: Remove the ansible_tenant
25 cisco.aci.aci_tenant:
26 <<: *aci_info
27 tenant: ansible_tenant
28 state: absent
29
30 - name: Delete Global DHCP relay policy
31 cisco.aci.aci_dhcp_relay:
32 <<: *aci_info
33 name: ansible_global_dhcp_relay
34 state: absent
35
36 - name: Add a new tenant
37 cisco.aci.aci_tenant:
38 <<: *aci_info
39 tenant: ansible_tenant
40 description: Ansible tenant
41 state: present
42
43 # CREATE DHCP RELAY
44 - name: Add a new DHCP relay policy
45 cisco.aci.aci_dhcp_relay:
46 <<: *aci_info
47 tenant: ansible_tenant
48 name: ansible_dhcp_relay
49 description: Ansible DHCP Relay
50 state: present
51 register: add_dhcp_relay
52
53 - name: Verify DHCP Relay creation
54 ansible.builtin.assert:
55 that:
56 - add_dhcp_relay is changed
57 - add_dhcp_relay.current.0.dhcpRelayP.attributes.annotation == 'orchestrator:ansible'
58 - add_dhcp_relay.current.0.dhcpRelayP.attributes.dn == "uni/tn-ansible_tenant/relayp-ansible_dhcp_relay"
59 - add_dhcp_relay.current.0.dhcpRelayP.attributes.name == "ansible_dhcp_relay"
60 - add_dhcp_relay.current.0.dhcpRelayP.attributes.owner == "tenant"
61 - add_dhcp_relay.current.0.dhcpRelayP.attributes.descr == "Ansible DHCP Relay"
62
63 # CREATE DHCP RELAY AGAIN TO TEST IDEMPOTENCE
64 - name: Add DHCP relay policy again
65 cisco.aci.aci_dhcp_relay:
66 <<: *aci_info
67 tenant: ansible_tenant
68 name: ansible_dhcp_relay
69 description: Ansible DHCP Relay
70 state: present
71 register: add_dhcp_relay_again
72
73 - name: Verify DHCP Relay idempotence
74 ansible.builtin.assert:
75 that:
76 - add_dhcp_relay_again is not changed
77 - add_dhcp_relay_again.current.0.dhcpRelayP.attributes.dn == "uni/tn-ansible_tenant/relayp-ansible_dhcp_relay"
78 - add_dhcp_relay_again.current.0.dhcpRelayP.attributes.name == "ansible_dhcp_relay"
79 - add_dhcp_relay_again.current.0.dhcpRelayP.attributes.owner == "tenant"
80 - add_dhcp_relay_again.current.0.dhcpRelayP.attributes.descr == "Ansible DHCP Relay"
81
82 # MODIFY DHCP RELAY
83 - name: Update DHCP relay policy
84 cisco.aci.aci_dhcp_relay:
85 <<: *aci_info
86 tenant: ansible_tenant
87 name: ansible_dhcp_relay
88 description: New Ansible DHCP Relay
89 state: present
90 register: update_dhcp_relay
91
92 - name: Verify DHCP Relay change
93 ansible.builtin.assert:
94 that:
95 - update_dhcp_relay is changed
96 - update_dhcp_relay.current.0.dhcpRelayP.attributes.dn == "uni/tn-ansible_tenant/relayp-ansible_dhcp_relay"
97 - update_dhcp_relay.current.0.dhcpRelayP.attributes.name == "ansible_dhcp_relay"
98 - update_dhcp_relay.current.0.dhcpRelayP.attributes.owner == "tenant"
99 - update_dhcp_relay.current.0.dhcpRelayP.attributes.descr == "New Ansible DHCP Relay"
100
101 - name: Add another DHCP relay policy for query all
102 cisco.aci.aci_dhcp_relay:
103 <<: *aci_info
104 tenant: ansible_tenant
105 name: ansible_dhcp_relay_2
106 state: present
107
108 # CREATE GLOBAL DHCP RELAY
109 - name: Add a new Global DHCP relay policy
110 cisco.aci.aci_dhcp_relay:
111 <<: *aci_info
112 name: ansible_global_dhcp_relay
113 description: Ansible Global DHCP Relay
114 state: present
115 register: add_global_dhcp_relay
116
117 - name: Verify Global DHCP Relay creation
118 ansible.builtin.assert:
119 that:
120 - add_global_dhcp_relay is changed
121 - add_global_dhcp_relay.current.0.dhcpRelayP.attributes.annotation == 'orchestrator:ansible'
122 - add_global_dhcp_relay.current.0.dhcpRelayP.attributes.dn == "uni/infra/relayp-ansible_global_dhcp_relay"
123 - add_global_dhcp_relay.current.0.dhcpRelayP.attributes.name == "ansible_global_dhcp_relay"
124 - add_global_dhcp_relay.current.0.dhcpRelayP.attributes.owner == "infra"
125 - add_global_dhcp_relay.current.0.dhcpRelayP.attributes.descr == "Ansible Global DHCP Relay"
126
127 # QUERY DHCP RELAY
128 - name: Query DHCP relay policy
129 cisco.aci.aci_dhcp_relay:
130 <<: *aci_info
131 tenant: ansible_tenant
132 name: ansible_dhcp_relay
133 state: query
134 register: query_dhcp_relay
135
136 - name: Verify DHCP Relay query
137 ansible.builtin.assert:
138 that:
139 - query_dhcp_relay is not changed
140 - query_dhcp_relay.current.0.dhcpRelayP.attributes.dn == "uni/tn-ansible_tenant/relayp-ansible_dhcp_relay"
141 - query_dhcp_relay.current.0.dhcpRelayP.attributes.name == "ansible_dhcp_relay"
142 - query_dhcp_relay.current.0.dhcpRelayP.attributes.owner == "tenant"
143 - query_dhcp_relay.current.0.dhcpRelayP.attributes.descr == "New Ansible DHCP Relay"
144
145 - name: Query all DHCP relays in ansible_tenant
146 cisco.aci.aci_dhcp_relay:
147 <<: *aci_info
148 tenant: ansible_tenant
149 state: query
150 register: query_dhcp_relay_all
151
152 - name: Verify query idempotence
153 ansible.builtin.assert:
154 that:
155 - query_dhcp_relay_all is not changed
156 - query_dhcp_relay_all.current.0.fvTenant.children | length >= 2
157
158 # QUERY GLOBAL DHCP RELAY
159 - name: Query Global DHCP relay policy
160 cisco.aci.aci_dhcp_relay:
161 <<: *aci_info
162 name: ansible_global_dhcp_relay
163 state: query
164 register: query_global_dhcp_relay
165
166 - name: Verify Global DHCP Relay query
167 ansible.builtin.assert:
168 that:
169 - query_global_dhcp_relay is not changed
170 - query_global_dhcp_relay.current.0.dhcpRelayP.attributes.dn == "uni/infra/relayp-ansible_global_dhcp_relay"
171 - query_global_dhcp_relay.current.0.dhcpRelayP.attributes.name == "ansible_global_dhcp_relay"
172 - query_global_dhcp_relay.current.0.dhcpRelayP.attributes.owner == "infra"
173 - query_global_dhcp_relay.current.0.dhcpRelayP.attributes.descr == "Ansible Global DHCP Relay"
174
175 - name: Query all DHCP relays
176 cisco.aci.aci_dhcp_relay:
177 <<: *aci_info
178 state: query
179 register: query_global_dhcp_relay_all
180
181 - name: Verify query idempotence for Global DHCP Relay
182 ansible.builtin.assert:
183 that:
184 - query_global_dhcp_relay_all is not changed
185 - query_global_dhcp_relay_all.current | length >= 3
186
187 # DELETE DHCP RELAY
188 - name: Delete DHCP relay policy
189 cisco.aci.aci_dhcp_relay:
190 <<: *aci_info
191 tenant: ansible_tenant
192 name: ansible_dhcp_relay
193 state: absent
194 register: delete_dhcp_relay
195
196 - name: Verify DHCP Relay deletion
197 ansible.builtin.assert:
198 that:
199 - delete_dhcp_relay is changed
200 - delete_dhcp_relay.current == []
201 - delete_dhcp_relay.previous.0.dhcpRelayP.attributes.dn == "uni/tn-ansible_tenant/relayp-ansible_dhcp_relay"
202 - delete_dhcp_relay.previous.0.dhcpRelayP.attributes.name == "ansible_dhcp_relay"
203 - delete_dhcp_relay.previous.0.dhcpRelayP.attributes.owner == "tenant"
204 - delete_dhcp_relay.previous.0.dhcpRelayP.attributes.descr == "New Ansible DHCP Relay"
205
206 - name: Delete DHCP relay policy again to test idempotence
207 cisco.aci.aci_dhcp_relay:
208 <<: *aci_info
209 tenant: ansible_tenant
210 name: ansible_dhcp_relay
211 state: absent
212 register: delete_dhcp_relay_again
213
214 - name: Verify DHCP Relay deletion idempotence
215 ansible.builtin.assert:
216 that:
217 - delete_dhcp_relay_again is not changed
218
219 # DELETE GLOBAL DHCP RELAY
220 - name: Delete Global DHCP relay policy
221 cisco.aci.aci_dhcp_relay:
222 <<: *aci_info
223 name: ansible_global_dhcp_relay
224 state: absent
225 register: delete_global_dhcp_relay
226
227 - name: Verify Global DHCP Relay deletion
228 ansible.builtin.assert:
229 that:
230 - delete_global_dhcp_relay is changed
231 - delete_global_dhcp_relay.current == []
232 - delete_global_dhcp_relay.previous.0.dhcpRelayP.attributes.dn == "uni/infra/relayp-ansible_global_dhcp_relay"
233 - delete_global_dhcp_relay.previous.0.dhcpRelayP.attributes.name == "ansible_global_dhcp_relay"
234 - delete_global_dhcp_relay.previous.0.dhcpRelayP.attributes.owner == "infra"
235 - delete_global_dhcp_relay.previous.0.dhcpRelayP.attributes.descr == "Ansible Global DHCP Relay"
236
237 # CLEAN ENVIRONMENT AGAIN
238 - name: Remove the ansible_tenant
239 cisco.aci.aci_tenant:
240 <<: *aci_info
241 tenant: ansible_tenant
242 state: absent