Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/gitlab_label/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 - name: Install required libs
12 pip:
13 name: python-gitlab
14 state: present
15
16 - block:
17 ###
18 ### Group label
19 ###
20
21 - name: Create {{ gitlab_project_group }}
22 gitlab_group:
23 api_url: "{{ gitlab_host }}"
24 validate_certs: true
25 api_token: "{{ gitlab_api_token }}"
26 name: "{{ gitlab_project_group }}"
27 state: present
28
29 - name: Purge all group labels for check_mode test
30 gitlab_label:
31 api_url: "{{ gitlab_host }}"
32 api_token: "{{ gitlab_api_token }}"
33 group: "{{ gitlab_project_group }}"
34 purge: true
35
36 - name: Group label - Add a label in check_mode
37 gitlab_label:
38 api_token: "{{ gitlab_api_token }}"
39 api_url: "{{ gitlab_host }}"
40 group: "{{ gitlab_project_group }}"
41 labels:
42 - name: "{{ gitlab_second_label }}"
43 color: "{{ gitlab_second_label_color }}"
44 check_mode: true
45 register: gitlab_group_label_state
46
47 - name: Group label - Check_mode state must be changed
48 assert:
49 that:
50 - gitlab_group_label_state is changed
51
52 - name: Group label - Create label {{ gitlab_first_label }} and {{ gitlab_second_label }}
53 gitlab_label:
54 api_token: "{{ gitlab_api_token }}"
55 api_url: "{{ gitlab_host }}"
56 group: "{{ gitlab_project_group }}"
57 labels:
58 - name: "{{ gitlab_first_label }}"
59 color: "{{ gitlab_first_label_color }}"
60 description: "{{ gitlab_first_label_description }}"
61 priority: "{{ gitlab_first_label_priority }}"
62 - name: "{{ gitlab_second_label }}"
63 color: "{{ gitlab_second_label_color }}"
64 state: present
65 register: gitlab_group_label_create
66
67 - name: Group label - Test Label Created
68 assert:
69 that:
70 - gitlab_group_label_create is changed
71 - gitlab_group_label_create.labels.added|length == 2
72 - gitlab_group_label_create.labels.untouched|length == 0
73 - gitlab_group_label_create.labels.removed|length == 0
74 - gitlab_group_label_create.labels.updated|length == 0
75 - gitlab_group_label_create.labels.added[0] == "{{ gitlab_first_label }}"
76 - gitlab_group_label_create.labels.added[1] == "{{ gitlab_second_label }}"
77
78 - name: Group label - Create Label ( Idempotency test )
79 gitlab_label:
80 api_token: "{{ gitlab_api_token }}"
81 api_url: "{{ gitlab_host }}"
82 group: "{{ gitlab_project_group }}"
83 labels:
84 - name: "{{ gitlab_first_label }}"
85 color: "{{ gitlab_first_label_color }}"
86 description: "{{ gitlab_first_label_description }}"
87 priority: "{{ gitlab_first_label_priority }}"
88 state: present
89 register: gitlab_group_label_create_idempotence
90
91 - name: Group label - Test Create Label is Idempotent
92 assert:
93 that:
94 - gitlab_group_label_create_idempotence is not changed
95
96 - name: Group label - Update Label {{ gitlab_first_label }} changing color
97 gitlab_label:
98 api_token: "{{ gitlab_api_token }}"
99 api_url: "{{ gitlab_host }}"
100 group: "{{ gitlab_project_group }}"
101 labels:
102 - name: "{{ gitlab_first_label }}"
103 color: "{{ gitlab_second_label_color }}"
104 state: present
105 register: gitlab_group_label_update
106
107 - name: Group label - Test Label Updated
108 assert:
109 that:
110 - gitlab_group_label_update.labels.added|length == 0
111 - gitlab_group_label_update.labels.untouched|length == 0
112 - gitlab_group_label_update.labels.removed|length == 0
113 - gitlab_group_label_update.labels.updated|length == 1
114 - gitlab_group_label_update.labels.updated[0] == "{{ gitlab_first_label }}"
115
116 - name: Group label - Change label {{ gitlab_second_label }} name to {{ gitlab_second_label_new_name }}
117 gitlab_label:
118 api_token: "{{ gitlab_api_token }}"
119 api_url: "{{ gitlab_host }}"
120 group: "{{ gitlab_project_group }}"
121 labels:
122 - name: "{{ gitlab_second_label }}"
123 new_name: "{{ gitlab_second_label_new_name }}"
124 state: present
125 register: gitlab_group_label_new_name
126
127 - name: Group label - Test Label name changed
128 assert:
129 that:
130 - gitlab_group_label_new_name.labels.added|length == 0
131 - gitlab_group_label_new_name.labels.untouched|length == 0
132 - gitlab_group_label_new_name.labels.removed|length == 0
133 - gitlab_group_label_new_name.labels.updated|length == 1
134 - gitlab_group_label_new_name.labels.updated[0] == "{{ gitlab_second_label }}"
135
136 - name: Group label - Change label name back to {{ gitlab_second_label }}
137 gitlab_label:
138 api_token: "{{ gitlab_api_token }}"
139 api_url: "{{ gitlab_host }}"
140 group: "{{ gitlab_project_group }}"
141 labels:
142 - name: "{{ gitlab_second_label_new_name }}"
143 new_name: "{{ gitlab_second_label }}"
144 state: present
145 register: gitlab_group_label_orig_name
146
147 - name: Group label - Test Label name changed back
148 assert:
149 that:
150 - gitlab_group_label_orig_name.labels.added|length == 0
151 - gitlab_group_label_orig_name.labels.untouched|length == 0
152 - gitlab_group_label_orig_name.labels.removed|length == 0
153 - gitlab_group_label_orig_name.labels.updated|length == 1
154 - gitlab_group_label_orig_name.labels.updated[0] == "{{ gitlab_second_label_new_name }}"
155
156 - name: Group label - Update Label Test ( Additions )
157 gitlab_label:
158 api_token: "{{ gitlab_api_token }}"
159 api_url: "{{ gitlab_host }}"
160 group: "{{ gitlab_project_group }}"
161 labels:
162 - name: "{{ gitlab_second_label }}"
163 description: "{{ gitlab_first_label_description }}"
164 priority: "{{ gitlab_first_label_priority }}"
165 state: present
166 register: gitlab_group_label_update_additions
167
168 - name: Group label - Test Label Updated ( Additions )
169 assert:
170 that:
171 - gitlab_group_label_update_additions.labels.added|length == 0
172 - gitlab_group_label_update_additions.labels.untouched|length == 0
173 - gitlab_group_label_update_additions.labels.removed|length == 0
174 - gitlab_group_label_update_additions.labels.updated|length == 1
175 - gitlab_group_label_update_additions.labels.updated[0] == "{{ gitlab_second_label }}"
176
177 - name: Group label - Delete Label {{ gitlab_second_label }}
178 gitlab_label:
179 api_token: "{{ gitlab_api_token }}"
180 api_url: "{{ gitlab_host }}"
181 group: "{{ gitlab_project_group }}"
182 labels:
183 - name: "{{ gitlab_second_label }}"
184 state: absent
185 register: gitlab_group_label_delete
186
187 - name: Group label - Test label is deleted
188 assert:
189 that:
190 - gitlab_group_label_delete is changed
191 - gitlab_group_label_delete.labels.added|length == 0
192 - gitlab_group_label_delete.labels.untouched|length == 0
193 - gitlab_group_label_delete.labels.removed|length == 1
194 - gitlab_group_label_delete.labels.updated|length == 0
195 - gitlab_group_label_delete.labels.removed[0] == "{{ gitlab_second_label }}"
196
197 - name: Group label - Create label {{ gitlab_second_label }} again purging the other
198 gitlab_label:
199 api_token: "{{ gitlab_api_token }}"
200 api_url: "{{ gitlab_host }}"
201 group: "{{ gitlab_project_group }}"
202 purge: true
203 labels:
204 - name: "{{ gitlab_second_label }}"
205 color: "{{ gitlab_second_label_color }}"
206 state: present
207 register: gitlab_group_label_create_purging
208
209 - name: Group label - Test Label Created again
210 assert:
211 that:
212 - gitlab_group_label_create_purging is changed
213 - gitlab_group_label_create_purging.labels.added|length == 1
214 - gitlab_group_label_create_purging.labels.untouched|length == 0
215 - gitlab_group_label_create_purging.labels.removed|length == 1
216 - gitlab_group_label_create_purging.labels.updated|length == 0
217 - gitlab_group_label_create_purging.labels.added[0] == "{{ gitlab_second_label }}"
218 - gitlab_group_label_create_purging.labels.removed[0] == "{{ gitlab_first_label }}"
219
220 ###
221 ### Project label
222 ###
223
224 - name: Create {{ gitlab_project_name }}
225 gitlab_project:
226 api_url: "{{ gitlab_host }}"
227 validate_certs: true
228 api_token: "{{ gitlab_api_token }}"
229 name: "{{ gitlab_project_name }}"
230 group: "{{ gitlab_project_group }}"
231 default_branch: "{{ gitlab_branch }}"
232 initialize_with_readme: true
233 state: present
234
235 - name: Purge all labels for check_mode test
236 gitlab_label:
237 api_url: "{{ gitlab_host }}"
238 api_token: "{{ gitlab_api_token }}"
239 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
240 purge: true
241
242 - name: Add a label in check_mode
243 gitlab_label:
244 api_token: "{{ gitlab_api_token }}"
245 api_url: "{{ gitlab_host }}"
246 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
247 labels:
248 - name: "{{ gitlab_second_label }}"
249 color: "{{ gitlab_second_label_color }}"
250 check_mode: true
251 register: gitlab_first_label_state
252
253 - name: Check_mode state must be changed
254 assert:
255 that:
256 - gitlab_first_label_state is changed
257
258 - name: Create label {{ gitlab_first_label }} and {{ gitlab_second_label }}
259 gitlab_label:
260 api_token: "{{ gitlab_api_token }}"
261 api_url: "{{ gitlab_host }}"
262 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
263 labels:
264 - name: "{{ gitlab_first_label }}"
265 color: "{{ gitlab_first_label_color }}"
266 description: "{{ gitlab_first_label_description }}"
267 priority: "{{ gitlab_first_label_priority }}"
268 - name: "{{ gitlab_second_label }}"
269 color: "{{ gitlab_second_label_color }}"
270 state: present
271 register: gitlab_first_label_create
272
273 - name: Test Label Created
274 assert:
275 that:
276 - gitlab_first_label_create is changed
277 - gitlab_first_label_create.labels.added|length == 2
278 - gitlab_first_label_create.labels.untouched|length == 0
279 - gitlab_first_label_create.labels.removed|length == 0
280 - gitlab_first_label_create.labels.updated|length == 0
281 - gitlab_first_label_create.labels.added[0] == "{{ gitlab_first_label }}"
282 - gitlab_first_label_create.labels.added[1] == "{{ gitlab_second_label }}"
283
284 - name: Create Label ( Idempotency test )
285 gitlab_label:
286 api_token: "{{ gitlab_api_token }}"
287 api_url: "{{ gitlab_host }}"
288 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
289 labels:
290 - name: "{{ gitlab_first_label }}"
291 color: "{{ gitlab_first_label_color }}"
292 description: "{{ gitlab_first_label_description }}"
293 priority: "{{ gitlab_first_label_priority }}"
294 state: present
295 register: gitlab_first_label_create_idempotence
296
297 - name: Test Create Label is Idempotent
298 assert:
299 that:
300 - gitlab_first_label_create_idempotence is not changed
301
302 - name: Update Label {{ gitlab_first_label }} changing color
303 gitlab_label:
304 api_token: "{{ gitlab_api_token }}"
305 api_url: "{{ gitlab_host }}"
306 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
307 labels:
308 - name: "{{ gitlab_first_label }}"
309 color: "{{ gitlab_second_label_color }}"
310 state: present
311 register: gitlab_first_label_update
312
313 - name: Test Label Updated
314 assert:
315 that:
316 - gitlab_first_label_update.labels.added|length == 0
317 - gitlab_first_label_update.labels.untouched|length == 0
318 - gitlab_first_label_update.labels.removed|length == 0
319 - gitlab_first_label_update.labels.updated|length == 1
320 - gitlab_first_label_update.labels.updated[0] == "{{ gitlab_first_label }}"
321
322 - name: Change label {{ gitlab_second_label }} name to {{ gitlab_second_label_new_name }}
323 gitlab_label:
324 api_token: "{{ gitlab_api_token }}"
325 api_url: "{{ gitlab_host }}"
326 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
327 labels:
328 - name: "{{ gitlab_second_label }}"
329 new_name: "{{ gitlab_second_label_new_name }}"
330 state: present
331 register: gitlab_first_label_new_name
332
333 - name: Test Label name changed
334 assert:
335 that:
336 - gitlab_first_label_new_name.labels.added|length == 0
337 - gitlab_first_label_new_name.labels.untouched|length == 0
338 - gitlab_first_label_new_name.labels.removed|length == 0
339 - gitlab_first_label_new_name.labels.updated|length == 1
340 - gitlab_first_label_new_name.labels.updated[0] == "{{ gitlab_second_label }}"
341
342 - name: Change label name back to {{ gitlab_second_label }}
343 gitlab_label:
344 api_token: "{{ gitlab_api_token }}"
345 api_url: "{{ gitlab_host }}"
346 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
347 labels:
348 - name: "{{ gitlab_second_label_new_name }}"
349 new_name: "{{ gitlab_second_label }}"
350 state: present
351 register: gitlab_first_label_orig_name
352
353 - name: Test Label name changed back
354 assert:
355 that:
356 - gitlab_first_label_orig_name.labels.added|length == 0
357 - gitlab_first_label_orig_name.labels.untouched|length == 0
358 - gitlab_first_label_orig_name.labels.removed|length == 0
359 - gitlab_first_label_orig_name.labels.updated|length == 1
360 - gitlab_first_label_orig_name.labels.updated[0] == "{{ gitlab_second_label_new_name }}"
361
362 - name: Update Label Test ( Additions )
363 gitlab_label:
364 api_token: "{{ gitlab_api_token }}"
365 api_url: "{{ gitlab_host }}"
366 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
367 labels:
368 - name: "{{ gitlab_second_label }}"
369 description: "{{ gitlab_first_label_description }}"
370 priority: "{{ gitlab_first_label_priority }}"
371 state: present
372 register: gitlab_first_label_update_additions
373
374 - name: Test Label Updated ( Additions )
375 assert:
376 that:
377 - gitlab_first_label_update_additions.labels.added|length == 0
378 - gitlab_first_label_update_additions.labels.untouched|length == 0
379 - gitlab_first_label_update_additions.labels.removed|length == 0
380 - gitlab_first_label_update_additions.labels.updated|length == 1
381 - gitlab_first_label_update_additions.labels.updated[0] == "{{ gitlab_second_label }}"
382
383 - name: Delete Label {{ gitlab_second_label }}
384 gitlab_label:
385 api_token: "{{ gitlab_api_token }}"
386 api_url: "{{ gitlab_host }}"
387 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
388 labels:
389 - name: "{{ gitlab_second_label }}"
390 state: absent
391 register: gitlab_first_label_delete
392
393 - name: Test label is deleted
394 assert:
395 that:
396 - gitlab_first_label_delete is changed
397 - gitlab_first_label_delete.labels.added|length == 0
398 - gitlab_first_label_delete.labels.untouched|length == 0
399 - gitlab_first_label_delete.labels.removed|length == 1
400 - gitlab_first_label_delete.labels.updated|length == 0
401 - gitlab_first_label_delete.labels.removed[0] == "{{ gitlab_second_label }}"
402
403 - name: Create label {{ gitlab_second_label }} again purging the other
404 gitlab_label:
405 api_token: "{{ gitlab_api_token }}"
406 api_url: "{{ gitlab_host }}"
407 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
408 purge: true
409 labels:
410 - name: "{{ gitlab_second_label }}"
411 color: "{{ gitlab_second_label_color }}"
412 state: present
413 register: gitlab_first_label_create_purging
414
415 - name: Test Label Created again
416 assert:
417 that:
418 - gitlab_first_label_create_purging is changed
419 - gitlab_first_label_create_purging.labels.added|length == 1
420 - gitlab_first_label_create_purging.labels.untouched|length == 0
421 - gitlab_first_label_create_purging.labels.removed|length == 1
422 - gitlab_first_label_create_purging.labels.updated|length == 0
423 - gitlab_first_label_create_purging.labels.added[0] == "{{ gitlab_second_label }}"
424 - gitlab_first_label_create_purging.labels.removed[0] == "{{ gitlab_first_label }}"
425
426 always:
427 - name: Delete Labels
428 gitlab_label:
429 api_token: "{{ gitlab_api_token }}"
430 api_url: "{{ gitlab_host }}"
431 project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
432 purge: true
433 labels:
434 - name: "{{ gitlab_first_label }}"
435 - name: "{{ gitlab_second_label }}"
436 state: absent
437 register: gitlab_first_label_always_delete
438
439 - name: Test label are deleted
440 assert:
441 that:
442 - gitlab_first_label_always_delete is changed
443 - gitlab_first_label_always_delete.labels.added|length == 0
444 - gitlab_first_label_always_delete.labels.untouched|length == 0
445 - gitlab_first_label_always_delete.labels.removed|length > 0
446 - gitlab_first_label_always_delete.labels.updated|length == 0
447
448 - name: Clean up {{ gitlab_project_name }}
449 gitlab_project:
450 api_url: "{{ gitlab_host }}"
451 validate_certs: false
452 api_token: "{{ gitlab_api_token }}"
453 name: "{{ gitlab_project_name }}"
454 group: "{{ gitlab_project_group }}"
455 state: absent
456
457 - name: Clean up {{ gitlab_project_group }}
458 gitlab_group:
459 api_url: "{{ gitlab_host }}"
460 validate_certs: true
461 api_token: "{{ gitlab_api_token }}"
462 name: "{{ gitlab_project_group }}"
463 state: absent