Debian Codegraph @

test/integration/targets/group/tasks/tests.yml

raw
1 ---
2 - name: ensure test groups are deleted before the test
3 group:
4 name: '{{ item }}'
5 state: absent
6 loop:
7 - ansibullgroup
8 - ansibullgroup2
9 - ansibullgroup3
10
11 - block:
12 ##
13 ## group add
14 ##
15
16 - name: create group (check mode)
17 group:
18 name: ansibullgroup
19 state: present
20 register: create_group_check
21 check_mode: true
22
23 - name: get result of create group (check mode)
24 script: 'grouplist.sh "{{ ansible_distribution }}"'
25 register: create_group_actual_check
26
27 - name: assert create group (check mode)
28 assert:
29 that:
30 - create_group_check is changed
31 - '"ansibullgroup" not in create_group_actual_check.stdout_lines'
32
33 - name: create group
34 group:
35 name: ansibullgroup
36 state: present
37 register: create_group
38
39 - name: get result of create group
40 script: 'grouplist.sh "{{ ansible_distribution }}"'
41 register: create_group_actual
42
43 - name: assert create group
44 assert:
45 that:
46 - create_group is changed
47 - create_group.gid is defined
48 - '"ansibullgroup" in create_group_actual.stdout_lines'
49
50 - name: create group (idempotent)
51 group:
52 name: ansibullgroup
53 state: present
54 register: create_group_again
55
56 - name: assert create group (idempotent)
57 assert:
58 that:
59 - not create_group_again is changed
60
61 ##
62 ## group check
63 ##
64
65 - name: run existing group check tests
66 group:
67 name: "{{ create_group_actual.stdout_lines|random }}"
68 state: present
69 with_sequence: start=1 end=5
70 register: group_test1
71
72 - name: validate results for testcase 1
73 assert:
74 that:
75 - group_test1.results is defined
76 - group_test1.results|length == 5
77
78 - name: validate change results for testcase 1
79 assert:
80 that:
81 - not group_test1 is changed
82
83 ##
84 ## group add with gid
85 ##
86
87 - name: get the next available gid
88 script: get_free_gid.py
89 args:
90 executable: '{{ ansible_python_interpreter }}'
91 register: gid
92
93 - name: create a group with a gid (check mode)
94 group:
95 name: ansibullgroup2
96 gid: '{{ gid.stdout_lines[0] }}'
97 state: present
98 register: create_group_gid_check
99 check_mode: true
100
101 - name: get result of create a group with a gid (check mode)
102 script: 'grouplist.sh "{{ ansible_distribution }}"'
103 register: create_group_gid_actual_check
104
105 - name: assert create group with a gid (check mode)
106 assert:
107 that:
108 - create_group_gid_check is changed
109 - '"ansibullgroup2" not in create_group_gid_actual_check.stdout_lines'
110
111 - name: create a group with a gid
112 group:
113 name: ansibullgroup2
114 gid: '{{ gid.stdout_lines[0] }}'
115 state: present
116 register: create_group_gid
117
118 - name: get gid of created group
119 script: "get_gid_for_group.py ansibullgroup2"
120 args:
121 executable: '{{ ansible_python_interpreter }}'
122 register: create_group_gid_actual
123
124 - name: assert create group with a gid
125 assert:
126 that:
127 - create_group_gid is changed
128 - create_group_gid.gid | int == gid.stdout_lines[0] | int
129 - create_group_gid_actual.stdout | trim | int == gid.stdout_lines[0] | int
130
131 - name: create a group with a gid (idempotent)
132 group:
133 name: ansibullgroup2
134 gid: '{{ gid.stdout_lines[0] }}'
135 state: present
136 register: create_group_gid_again
137
138 - name: assert create group with a gid (idempotent)
139 assert:
140 that:
141 - not create_group_gid_again is changed
142 - create_group_gid_again.gid | int == gid.stdout_lines[0] | int
143
144 - block:
145 - name: create a group with a non-unique gid
146 group:
147 name: ansibullgroup3
148 gid: '{{ gid.stdout_lines[0] }}'
149 non_unique: true
150 state: present
151 register: create_group_gid_non_unique
152
153 - name: validate gid required with non_unique
154 group:
155 name: foo
156 non_unique: true
157 register: missing_gid
158 ignore_errors: true
159
160 - name: assert create group with a non unique gid
161 assert:
162 that:
163 - create_group_gid_non_unique is changed
164 - create_group_gid_non_unique.gid | int == gid.stdout_lines[0] | int
165 - missing_gid is failed
166 when: ansible_facts.distribution not in ['MacOSX', 'Alpine']
167
168 ##
169 ## group remove
170 ##
171
172 - name: delete group (check mode)
173 group:
174 name: ansibullgroup
175 state: absent
176 register: delete_group_check
177 check_mode: true
178
179 - name: get result of delete group (check mode)
180 script: 'grouplist.sh "{{ ansible_distribution }}"'
181 register: delete_group_actual_check
182
183 - name: assert delete group (check mode)
184 assert:
185 that:
186 - delete_group_check is changed
187 - '"ansibullgroup" in delete_group_actual_check.stdout_lines'
188
189 - name: delete group
190 group:
191 name: ansibullgroup
192 state: absent
193 register: delete_group
194
195 - name: get result of delete group
196 script: 'grouplist.sh "{{ ansible_distribution }}"'
197 register: delete_group_actual
198
199 - name: assert delete group
200 assert:
201 that:
202 - delete_group is changed
203 - '"ansibullgroup" not in delete_group_actual.stdout_lines'
204
205 - name: delete group (idempotent)
206 group:
207 name: ansibullgroup
208 state: absent
209 register: delete_group_again
210
211 - name: assert delete group (idempotent)
212 assert:
213 that:
214 - not delete_group_again is changed
215
216 - name: Ensure lgroupadd is present
217 action: "{{ ansible_facts.pkg_mgr }}"
218 args:
219 name: libuser
220 state: present
221 when: ansible_facts.system in ['Linux'] and ansible_distribution != 'Alpine'
222 tags:
223 - user_test_local_mode
224
225 - name: Ensure lgroupadd is present - Alpine
226 command: apk add -U libuser
227 when: ansible_distribution == 'Alpine'
228 tags:
229 - user_test_local_mode
230
231 # https://github.com/ansible/ansible/issues/56481
232 - block:
233 - name: Test duplicate GID with local=yes
234 group:
235 name: "{{ item }}"
236 gid: 1337
237 local: true
238 loop:
239 - group1_local_test
240 - group2_local_test
241 ignore_errors: true
242 register: local_duplicate_gid_result
243
244 - assert:
245 that:
246 - local_duplicate_gid_result['results'][0] is success
247 - local_duplicate_gid_result['results'][1]['msg'] == "GID '1337' already exists with group 'group1_local_test'"
248 always:
249 - name: Cleanup
250 group:
251 name: group1_local_test
252 state: absent
253 # only applicable to Linux, limit further to CentOS where 'luseradd' is installed
254 when: ansible_distribution == 'CentOS'
255
256 # https://github.com/ansible/ansible/pull/59769
257 - block:
258 - name: create a local group with a gid
259 group:
260 name: group1_local_test
261 gid: 1337
262 local: true
263 state: present
264 register: create_local_group_gid
265
266 - name: get gid of created local group
267 script: "get_gid_for_group.py group1_local_test"
268 args:
269 executable: '{{ ansible_python_interpreter }}'
270 register: create_local_group_gid_actual
271
272 - name: assert create local group with a gid
273 assert:
274 that:
275 - create_local_group_gid is changed
276 - create_local_group_gid.gid | int == 1337 | int
277 - create_local_group_gid_actual.stdout | trim | int == 1337 | int
278
279 - name: create a local group with a gid (idempotent)
280 group:
281 name: group1_local_test
282 gid: 1337
283 state: present
284 register: create_local_group_gid_again
285
286 - name: assert create local group with a gid (idempotent)
287 assert:
288 that:
289 - not create_local_group_gid_again is changed
290 - create_local_group_gid_again.gid | int == 1337 | int
291 always:
292 - name: Cleanup create local group with a gid
293 group:
294 name: group1_local_test
295 state: absent
296 # only applicable to Linux, limit further to CentOS where 'luseradd' is installed
297 when: ansible_distribution == 'CentOS'
298
299 # https://github.com/ansible/ansible/pull/59772
300 - block:
301 - name: create group with a gid
302 group:
303 name: group1_test
304 gid: 1337
305 local: false
306 state: present
307 register: create_group_gid
308
309 - name: get gid of created group
310 script: "get_gid_for_group.py group1_test"
311 args:
312 executable: '{{ ansible_python_interpreter }}'
313 register: create_group_gid_actual
314
315 - name: assert create group with a gid
316 assert:
317 that:
318 - create_group_gid is changed
319 - create_group_gid.gid | int == 1337 | int
320 - create_group_gid_actual.stdout | trim | int == 1337 | int
321
322 - name: create local group with the same gid
323 group:
324 name: group1_test
325 gid: 1337
326 local: true
327 state: present
328 register: create_local_group_gid
329
330 - name: assert create local group with a gid
331 assert:
332 that:
333 - create_local_group_gid.gid | int == 1337 | int
334 always:
335 - name: Cleanup create group with a gid
336 group:
337 name: group1_test
338 local: false
339 state: absent
340 - name: Cleanup create local group with the same gid
341 group:
342 name: group1_test
343 local: true
344 state: absent
345 # only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
346 when: ansible_distribution == 'CentOS'
347
348 # https://github.com/ansible/ansible/pull/78172
349 - block:
350 - name: Create a group
351 group:
352 name: groupdeltest
353 state: present
354
355 - name: Create user with primary group of groupdeltest
356 user:
357 name: groupdeluser
358 group: groupdeltest
359 state: present
360
361 - name: Show we can't delete the group usually
362 group:
363 name: groupdeltest
364 state: absent
365 ignore_errors: true
366 register: failed_delete
367
368 - name: assert we couldn't delete the group
369 assert:
370 that:
371 - failed_delete is failed
372
373 - name: force delete the group
374 group:
375 name: groupdeltest
376 force: true
377 state: absent
378
379 always:
380 - name: Cleanup user
381 user:
382 name: groupdeluser
383 state: absent
384
385 - name: Cleanup group
386 group:
387 name: groupdeltest
388 state: absent
389 when: ansible_distribution not in ["MacOSX", "Alpine", "FreeBSD"]
390
391 # https://github.com/ansible/ansible/issues/85565
392 - block:
393 - name: Create a group
394 group:
395 name: groupdeltest
396 state: present
397
398 - name: Use force to delete the group
399 group:
400 name: groupdeltest
401 state: absent
402 force: true
403 ignore_errors: true
404 register: force_delete
405
406 - name: assert an error occurred while deleting the group with force=true
407 assert:
408 that:
409 - force_delete is failed
410 - "'The force option is not supported' in force_delete.msg"
411
412 always:
413 - name: Cleanup group
414 group:
415 name: groupdeltest
416 state: absent
417
418 when: ansible_distribution in ["MacOSX", "Alpine", "FreeBSD"]
419
420 # create system group
421
422 - name: remove group
423 group:
424 name: ansibullgroup
425 state: absent
426
427 - name: create system group
428 group:
429 name: ansibullgroup
430 state: present
431 system: true
432
433 always:
434 - name: remove test groups after test
435 group:
436 name: '{{ item }}'
437 state: absent
438 loop:
439 - ansibullgroup
440 - ansibullgroup2
441 - ansibullgroup3