Debian Codegraph @

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

raw
1 # Test code for the ACI modules
2 # Copyright: (c) 2017, Dag Wieers (dagwieers) <[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 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 - name: Uninstall dateutil for error checking
12 ansible.builtin.pip: &dateutil
13 name: python-dateutil
14 state: absent
15 ignore_errors: true # ignore errors to because of multiple executions for hosts at the same time
16
17 - name: Set vars
18 ansible.builtin.set_fact:
19 aci_info: &aci_info
20 host: "{{ aci_hostname }}"
21 username: "{{ aci_username }}"
22 password: "{{ aci_password }}"
23 validate_certs: '{{ aci_validate_certs | default(false) }}'
24 use_ssl: '{{ aci_use_ssl | default(true) }}'
25 use_proxy: '{{ aci_use_proxy | default(true) }}'
26 output_level: '{{ aci_use_proxy | default("info") }}'
27
28 - name: Query system information to fetch version
29 cisco.aci.aci_system:
30 <<: *aci_info
31 id: 1
32 state: query
33 register: version
34
35 # ADD USER
36 - name: Add user without dateutil installed (error)
37 cisco.aci.aci_aaa_user: &user_present
38 <<: *aci_info
39 aaa_user: ansible
40 description: Ansible test user
41 email: [email protected]
42 enabled: true
43 expiration: never
44 expires: false
45 first_name: Test
46 last_name: User
47 phone: 1-234-555-678
48 ignore_errors: true
49 register: err_no_python_dateutil
50
51 - name: Verify add user
52 ansible.builtin.assert:
53 that:
54 - err_no_python_dateutil.msg == "dateutil required for this module"
55
56 - name: Install dateutil
57 ansible.builtin.pip:
58 <<: *dateutil
59 state: present
60 ignore_errors: true # ignore errors to because of multiple executions for hosts at the same time
61
62 # CLEAN ENVIRONMENT
63 - name: Remove any pre-existing user
64 cisco.aci.aci_aaa_user: &user_absent
65 <<: *aci_info
66 aaa_user: ansible
67 state: absent
68
69 # ADD USER
70 - name: Add user (check_mode)
71 cisco.aci.aci_aaa_user: *user_present
72 check_mode: true
73 register: cm_add_user
74
75 # NOTE: Setting password is not idempotent, see #35544
76 - name: Add user (normal mode)
77 cisco.aci.aci_aaa_user: &user_present_pass
78 <<: *user_present
79 # changed password because password strength check is triggered on the 6.0(2h) version, thus failing testcase
80 aaa_password: khsaubf@3ijsdn!!2#%nbsh
81 register: nm_add_user
82
83 - name: Add user again (check mode)
84 cisco.aci.aci_aaa_user: *user_present
85 check_mode: true
86 register: cm_add_user_again
87
88 - name: Add user again (normal mode)
89 cisco.aci.aci_aaa_user: *user_present
90 register: nm_add_user_again
91
92 - name: Verify add user
93 ansible.builtin.assert:
94 that:
95 - cm_add_user is changed
96 - nm_add_user is changed
97 - nm_add_user.current.0.aaaUser.attributes.annotation == 'orchestrator:ansible'
98 - nm_add_user.current.0.aaaUser.attributes.descr == 'Ansible test user'
99 - nm_add_user.proposed.aaaUser.attributes.pwd == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
100 - cm_add_user_again is not changed
101 - nm_add_user_again is not changed
102 - nm_add_user_again.current.0.aaaUser.attributes.descr == 'Ansible test user'
103
104 # VERSION SPECIFIC TESTS
105 - name: Test updating a password
106 when: version.current.0.topSystem.attributes.version is version('6.0', '>=')
107 block:
108 # Can't use previous 5 passwords
109 - name: Update user with no password change
110 cisco.aci.aci_aaa_user:
111 <<: *user_present_pass
112 ignore_errors: true
113 register: nm_add_user_no_password_change
114
115 - name: Update user with password change
116 cisco.aci.aci_aaa_user:
117 <<: *user_present
118 aaa_password: khsaubf@3ijsdn!!2#%nbsh1
119 register: nm_add_user_password_change
120
121 - name: Verify add user
122 ansible.builtin.assert:
123 that:
124 # Idempotency is not supported when password is set
125 - nm_add_user_password_change is changed
126 - nm_add_user_password_change.proposed.aaaUser.attributes.pwd == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
127 - nm_add_user_password_change.previous.0.aaaUser.attributes.pwd is undefined
128 - nm_add_user_password_change.current.0.aaaUser.attributes.pwd is undefined
129 - nm_add_user_no_password_change.msg == "APIC Error 1{{":"}} Password history check{{":"}} user ansible should not use previous 5 passwords"
130
131 # MODIFY USER
132 - name: Modify user (check_mode)
133 cisco.aci.aci_aaa_user: &user_changed
134 <<: *aci_info
135 aaa_user: ansible
136 description: Ansible test user for integration tests
137 email: [email protected]
138 expiration: '2123-12-12'
139 expires: true
140 phone: 2-345-555-678
141 check_mode: true
142 register: cm_modify_user
143
144 - name: Error wrong expiration (error)
145 cisco.aci.aci_aaa_user:
146 <<: *user_changed
147 expiration: wrong_expiration
148 ignore_errors: true
149 register: err_modify_user_expiration
150
151 - name: Modify user (normal mode)
152 cisco.aci.aci_aaa_user: *user_changed
153 register: nm_modify_user
154
155 - name: Modify user again (check mode)
156 cisco.aci.aci_aaa_user: *user_changed
157 check_mode: true
158 register: cm_modify_user_again
159
160 - name: Modify user again (normal mode)
161 cisco.aci.aci_aaa_user: *user_changed
162 register: nm_modify_user_again
163
164 - name: Verify modify user
165 ansible.builtin.assert:
166 that:
167 - cm_modify_user is changed
168 - err_modify_user_expiration.msg == "Failed to parse date format 'wrong_expiration', Unknown string format{{":"}} wrong_expiration"
169 - nm_modify_user is changed
170 - nm_modify_user.current.0.aaaUser.attributes.descr == 'Ansible test user for integration tests'
171 - cm_modify_user_again is not changed
172 - nm_modify_user_again is not changed
173 - nm_modify_user_again.current.0.aaaUser.attributes.descr == 'Ansible test user for integration tests'
174
175
176 # CLEAR PASSWORD HISTORY
177 - name: Clear password history (check_mode)
178 cisco.aci.aci_aaa_user: &clear_password_history
179 <<: *aci_info
180 aaa_user: ansible
181 clear_password_history: true
182 check_mode: true
183 register: cm_clear_password_history
184
185 - name: Clear password history (normal mode)
186 cisco.aci.aci_aaa_user: *clear_password_history
187 register: nm_clear_password_history
188
189 - name: Clear password history (check mode)
190 cisco.aci.aci_aaa_user: *clear_password_history
191 check_mode: true
192 register: cm_clear_password_history_again
193
194 - name: Clear password history (normal mode)
195 cisco.aci.aci_aaa_user: *clear_password_history
196 register: nm_clear_password_history_again
197
198 - name: Verify clear password history
199 ansible.builtin.assert:
200 that:
201 # NOTE: Clearing password history is a changing action, everytime
202 - cm_clear_password_history is changed
203 - nm_clear_password_history is changed
204 - cm_clear_password_history_again is changed
205 - nm_clear_password_history_again is changed
206
207
208 # QUERY ALL USERS
209 - name: Query all users (check_mode)
210 cisco.aci.aci_aaa_user: &user_query
211 <<: *aci_info
212 aaa_user: ansible
213 state: query
214 check_mode: true
215 register: cm_query_all_users
216
217 - name: Query all users (normal mode)
218 cisco.aci.aci_aaa_user: *user_query
219 register: nm_query_all_users
220
221 - name: Verify query_all_users
222 ansible.builtin.assert:
223 that:
224 - cm_query_all_users is not changed
225 - nm_query_all_users is not changed
226 # NOTE: Order of users is not stable between calls
227 #- cm_query_all_users == nm_query_all_users
228
229
230 # QUERY OUR USER
231 - name: Query our user (check_mode)
232 cisco.aci.aci_aaa_user:
233 <<: *user_query
234 check_mode: true
235 register: cm_query_user
236
237 - name: Query our user (normal mode)
238 cisco.aci.aci_aaa_user:
239 <<: *user_query
240 register: nm_query_user
241
242 - name: Verify query_user
243 ansible.builtin.assert:
244 that:
245 - cm_query_user is not changed
246 - nm_query_user is not changed
247 - cm_query_user == nm_query_user
248 - nm_query_user.current.0.aaaUser.attributes.accountStatus == 'active'
249 - nm_query_user.current.0.aaaUser.attributes.descr == 'Ansible test user for integration tests'
250 - nm_query_user.current.0.aaaUser.attributes.email == '[email protected]'
251 - nm_query_user.current.0.aaaUser.attributes.expiration == '2123-12-12T00:00:00.000+00:00'
252 - nm_query_user.current.0.aaaUser.attributes.expires == 'yes'
253 - nm_query_user.current.0.aaaUser.attributes.phone == '2-345-555-678'
254
255
256 # REMOVE USER
257 - name: Remove user (check_mode)
258 cisco.aci.aci_aaa_user: *user_absent
259 check_mode: true
260 register: cm_remove_user
261
262 - name: Remove user (normal mode)
263 cisco.aci.aci_aaa_user: *user_absent
264 register: nm_remove_user
265
266 - name: Remove user again (check_mode)
267 cisco.aci.aci_aaa_user: *user_absent
268 check_mode: true
269 register: cm_remove_user_again
270
271 - name: Remove user again (normal mode)
272 cisco.aci.aci_aaa_user: *user_absent
273 register: nm_remove_user_again
274
275 - name: Verify remove_user
276 ansible.builtin.assert:
277 that:
278 - cm_remove_user is changed
279 - nm_remove_user is changed
280 - cm_remove_user_again is not changed
281 - nm_remove_user_again is not changed