Debian Codegraph @

test/integration/targets/roles_arg_spec/test.yml

raw
1 ---
2 - hosts: localhost
3 gather_facts: false
4 roles:
5 - { role: a, a_str: "roles" }
6
7 vars:
8 INT_VALUE: 42
9
10 tasks:
11
12 - name: "Valid simple role usage with include_role"
13 include_role:
14 name: a
15 vars:
16 a_str: "include_role"
17
18 - name: "Valid simple role usage with import_role"
19 import_role:
20 name: a
21 vars:
22 a_str: "import_role"
23
24 - name: "Valid role usage (more args)"
25 include_role:
26 name: b
27 vars:
28 b_str: "xyz"
29 b_int: 5
30 b_bool: true
31
32 - name: "Valid simple role usage with include_role of different entry point"
33 include_role:
34 name: a
35 tasks_from: "alternate"
36 vars:
37 a_int: 256
38
39 - name: "Valid simple role usage with import_role of different entry point"
40 import_role:
41 name: a
42 tasks_from: "alternate"
43 vars:
44 a_int: 512
45
46 - name: "Valid simple role usage with a templated value"
47 import_role:
48 name: a
49 vars:
50 a_int: "{{ INT_VALUE }}"
51 a_str: "import_role"
52
53 - name: "Call role entry point that is defined, but has no spec data"
54 import_role:
55 name: a
56 tasks_from: "no_spec_entrypoint"
57
58 - name: "New play to reset vars: Test include_role fails"
59 hosts: localhost
60 gather_facts: false
61 vars:
62 expected_returned_spec:
63 b_bool:
64 required: true
65 type: "bool"
66 b_int:
67 required: true
68 type: "int"
69 b_str:
70 required: true
71 type: "str"
72
73 tasks:
74 - block:
75 - name: "Invalid role usage"
76 include_role:
77 name: b
78 vars:
79 b_bool: 7
80
81 - fail:
82 msg: "Should not get here"
83
84 rescue:
85 - debug:
86 var: ansible_failed_result
87
88 - name: "Validate failure"
89 assert:
90 that:
91 - ansible_failed_task.name == "Validating arguments against arg spec 'main' - Main entry point for role B."
92 - ansible_failed_result.argument_errors | length == 2
93 - "'missing required arguments: b_int, b_str' in ansible_failed_result.argument_errors"
94 - ansible_failed_result.validate_args_context.argument_spec_name == "main"
95 - ansible_failed_result.validate_args_context.name == "b"
96 - ansible_failed_result.validate_args_context.type == "role"
97 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/b')"
98 - ansible_failed_result.argument_spec_data == expected_returned_spec
99
100
101 - name: "New play to reset vars: Test import_role fails"
102 hosts: localhost
103 gather_facts: false
104 vars:
105 expected_returned_spec:
106 b_bool:
107 required: true
108 type: "bool"
109 b_int:
110 required: true
111 type: "int"
112 b_str:
113 required: true
114 type: "str"
115
116 tasks:
117 - block:
118 - name: "Invalid role usage"
119 import_role:
120 name: b
121 vars:
122 b_bool: 7
123
124 - fail:
125 msg: "Should not get here"
126
127 rescue:
128 - debug:
129 var: ansible_failed_result
130
131 - name: "Validate failure"
132 assert:
133 that:
134 - ansible_failed_task.name == "Validating arguments against arg spec 'main' - Main entry point for role B."
135 - ansible_failed_result.argument_errors | length == 2
136 - "'missing required arguments: b_int, b_str' in ansible_failed_result.argument_errors"
137 - ansible_failed_result.validate_args_context.argument_spec_name == "main"
138 - ansible_failed_result.validate_args_context.name == "b"
139 - ansible_failed_result.validate_args_context.type == "role"
140 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/b')"
141 - ansible_failed_result.argument_spec_data == expected_returned_spec
142
143
144 - name: "New play to reset vars: Test nested role including/importing role succeeds"
145 hosts: localhost
146 gather_facts: false
147 vars:
148 c_dict: {}
149 c_int: 1
150 c_list: []
151 c_raw: ~
152 a_str: "some string"
153 a_int: 42
154 tasks:
155 - name: "Test import_role of role C"
156 import_role:
157 name: c
158
159 - name: "Test include_role of role C"
160 include_role:
161 name: c
162
163 - name: "New play to reset vars: Test nested role including/importing role fails with null required options"
164 hosts: localhost
165 gather_facts: false
166 vars:
167 a_main_spec:
168 a_str:
169 required: true
170 type: "str"
171 c_main_spec:
172 c_int:
173 required: true
174 type: "int"
175 c_list:
176 required: true
177 type: "list"
178 c_dict:
179 required: true
180 type: "dict"
181 c_raw:
182 required: true
183 type: "raw"
184 # role c calls a's main and alternate entrypoints
185 a_str: ''
186 c_dict: {}
187 c_int: 0
188 c_list: []
189 c_raw: ~
190 tasks:
191 - name: test type coercion fails on None for required int
192 block:
193 - name: "Test import_role of role C (missing c_int)"
194 import_role:
195 name: c
196 vars:
197 c_int: ~
198 - fail:
199 msg: "Should not get here"
200 rescue:
201 - debug:
202 var: ansible_failed_result
203 - name: "Validate import_role failure"
204 assert:
205 that:
206 # NOTE: a bug here that prevents us from getting ansible_failed_task
207 - ansible_failed_result.argument_errors == [error]
208 - ansible_failed_result.argument_spec_data == c_main_spec
209 vars:
210 error: >-
211 argument 'c_int' is of type NoneType and we were unable to convert to int: "None" cannot be converted to an int
212
213 - name: test type coercion fails on None for required list
214 block:
215 - name: "Test import_role of role C (missing c_list)"
216 import_role:
217 name: c
218 vars:
219 c_list: ~
220 - fail:
221 msg: "Should not get here"
222 rescue:
223 - debug:
224 var: ansible_failed_result
225 - name: "Validate import_role failure"
226 assert:
227 that:
228 # NOTE: a bug here that prevents us from getting ansible_failed_task
229 - ansible_failed_result.argument_errors == [error]
230 - ansible_failed_result.argument_spec_data == c_main_spec
231 vars:
232 error: >-
233 argument 'c_list' is of type NoneType and we were unable to convert to list:
234 <class 'NoneType'> cannot be converted to a list
235
236 - name: test type coercion fails on None for required dict
237 block:
238 - name: "Test import_role of role C (missing c_dict)"
239 import_role:
240 name: c
241 vars:
242 c_dict: ~
243 - fail:
244 msg: "Should not get here"
245 rescue:
246 - debug:
247 var: ansible_failed_result
248 - name: "Validate import_role failure"
249 assert:
250 that:
251 # NOTE: a bug here that prevents us from getting ansible_failed_task
252 - ansible_failed_result.argument_errors == [error]
253 - ansible_failed_result.argument_spec_data == c_main_spec
254 vars:
255 error: >-
256 argument 'c_dict' is of type NoneType and we were unable to convert to dict:
257 <class 'NoneType'> cannot be converted to a dict
258
259 - name: "New play to reset vars: Test nested role including/importing role fails"
260 hosts: localhost
261 gather_facts: false
262 vars:
263 main_expected_returned_spec:
264 a_str:
265 required: true
266 type: "str"
267 alternate_expected_returned_spec:
268 a_int:
269 required: true
270 type: "int"
271
272 c_int: 100
273 c_list: []
274 c_dict: {}
275 c_raw: ~
276 tasks:
277 - block:
278 - name: "Test import_role of role C (missing a_str)"
279 import_role:
280 name: c
281
282 - fail:
283 msg: "Should not get here"
284
285 rescue:
286 - debug:
287 var: ansible_failed_result
288 - name: "Validate import_role failure"
289 assert:
290 that:
291 # NOTE: a bug here that prevents us from getting ansible_failed_task
292 - ansible_failed_result.argument_errors | length == 1
293 - "'missing required arguments: a_str' in ansible_failed_result.argument_errors"
294 - ansible_failed_result.validate_args_context.argument_spec_name == "main"
295 - ansible_failed_result.validate_args_context.name == "a"
296 - ansible_failed_result.validate_args_context.type == "role"
297 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/a')"
298 - ansible_failed_result.argument_spec_data == main_expected_returned_spec
299
300 - block:
301 - name: "Test include_role of role C (missing a_int from `alternate` entry point)"
302 include_role:
303 name: c
304 vars:
305 a_str: "some string"
306
307 - fail:
308 msg: "Should not get here"
309
310 rescue:
311 - debug:
312 var: ansible_failed_result
313 - name: "Validate include_role failure"
314 assert:
315 that:
316 # NOTE: a bug here that prevents us from getting ansible_failed_task
317 - ansible_failed_result.argument_errors | length == 1
318 - "'missing required arguments: a_int' in ansible_failed_result.argument_errors"
319 - ansible_failed_result.validate_args_context.argument_spec_name == "alternate"
320 - ansible_failed_result.validate_args_context.name == "a"
321 - ansible_failed_result.validate_args_context.type == "role"
322 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/a')"
323 - ansible_failed_result.argument_spec_data == alternate_expected_returned_spec
324
325 - name: "New play to reset vars: Test role with no tasks can fail"
326 hosts: localhost
327 gather_facts: false
328 tasks:
329 - block:
330 - name: "Test import_role of role role_with_no_tasks (missing a_str)"
331 import_role:
332 name: role_with_no_tasks
333
334 - fail:
335 msg: "Should not get here"
336
337 rescue:
338 - debug:
339 var: ansible_failed_result
340 - name: "Validate import_role failure"
341 assert:
342 that:
343 # NOTE: a bug here that prevents us from getting ansible_failed_task
344 - ansible_failed_result.argument_errors | length == 1
345 - "'missing required arguments: a_str' in ansible_failed_result.argument_errors"
346 - ansible_failed_result.validate_args_context.argument_spec_name == "main"
347 - ansible_failed_result.validate_args_context.name == "role_with_no_tasks"
348 - ansible_failed_result.validate_args_context.type == "role"
349 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/role_with_no_tasks')"
350
351 - name: "New play to reset vars: Test disabling role validation with rolespec_validate=False"
352 hosts: localhost
353 gather_facts: false
354 tasks:
355 - block:
356 - name: "Test import_role of role C (missing a_str), but validation turned off"
357 import_role:
358 name: c
359 rolespec_validate: False
360 - fail:
361 msg: "Should not get here"
362
363 rescue:
364 - debug:
365 var: ansible_failed_result
366 - name: "Validate import_role failure"
367 assert:
368 that:
369 # We expect the role to actually run, but will fail because an undefined variable was referenced
370 # and validation wasn't performed up front (thus not returning 'argument_errors').
371 - "'argument_errors' not in ansible_failed_result"
372 - |
373 ansible_failed_result.msg is contains "'c_int' is undefined"
374
375 - name: "New play to reset vars: Test collection-based role"
376 hosts: localhost
377 gather_facts: false
378 tasks:
379 - name: "Valid collection-based role usage"
380 import_role:
381 name: "foo.bar.blah"
382 vars:
383 blah_str: "some string"
384
385
386 - name: "New play to reset vars: Test collection-based role will fail"
387 hosts: localhost
388 gather_facts: false
389 tasks:
390 - block:
391 - name: "Invalid collection-based role usage"
392 import_role:
393 name: "foo.bar.blah"
394 - fail:
395 msg: "Should not get here"
396 rescue:
397 - debug: var=ansible_failed_result
398 - name: "Validate import_role failure for collection-based role"
399 assert:
400 that:
401 - ansible_failed_result.argument_errors | length == 1
402 - "'missing required arguments: blah_str' in ansible_failed_result.argument_errors"
403 - ansible_failed_result.validate_args_context.argument_spec_name == "main"
404 - ansible_failed_result.validate_args_context.name == "blah"
405 - ansible_failed_result.validate_args_context.type == "role"
406 - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/collections/ansible_collections/foo/bar/roles/blah')"
407
408 - name: "New play to reset vars: Test templating succeeds"
409 hosts: localhost
410 gather_facts: false
411 vars:
412 value_some_choices: "choice2"
413 value_some_list: [1.5]
414 value_some_dict: {"some_key": "some_value"}
415 value_some_int: 1
416 value_some_float: 1.5
417 value_some_json: '{[1, 3, 3] 345345|45v<#!}'
418 value_some_jsonarg: {"foo": [1, 3, 3]}
419 value_some_second_level: True
420 value_third_level: 5
421 value_some_unregistered_secret1: SECRET1
422 value_some_unregistered_secret2: SECRET2
423 tasks:
424 - block:
425 - include_role:
426 name: test1
427 vars:
428 some_choices: "{{ value_some_choices }}"
429 some_list: "{{ value_some_list }}"
430 some_dict: "{{ value_some_dict }}"
431 some_int: "{{ value_some_int }}"
432 some_float: "{{ value_some_float }}"
433 some_json: "{{ value_some_json }}"
434 some_jsonarg: "{{ value_some_jsonarg }}"
435 some_dict_options:
436 some_second_level: "{{ value_some_second_level }}"
437 some_secret: "{{ value_some_unregistered_secret1 }}"
438 multi_level_option:
439 second_level:
440 third_level: "{{ value_third_level }}"
441 second_level_secret: "{{ value_some_unregistered_secret2 }}"
442
443 - name: Display value registered as no_log in the argument spec
444 debug:
445 msg: "{{ value_some_unregistered_secret1 }} {{ value_some_unregistered_secret2 }}"
446 rescue:
447 - debug: var=ansible_failed_result
448 - fail:
449 msg: "Should not get here"
450
451 - name: "New play to reset vars: Test empty argument_specs.yml"
452 hosts: localhost
453 gather_facts: false
454 tasks:
455 - name: Import role with an empty argument_specs.yml
456 import_role:
457 name: empty_file
458
459 - name: "New play to reset vars: Test empty argument_specs key"
460 hosts: localhost
461 gather_facts: false
462 tasks:
463 - name: Import role with an empty argument_specs key
464 import_role:
465 name: empty_argspec