Debian Codegraph @

test/integration/targets/module_defaults/tasks/main.yml

raw
1 - name: main block
2 vars:
3 test_file: /tmp/ansible-test.module_defaults.foo
4 module_defaults:
5 debug:
6 msg: test {{ "default" }}
7 file:
8 path: '{{ test_file }}'
9 block:
10 - debug:
11 register: foo
12
13 - local_action:
14 module: debug
15 register: local_action_foo
16
17 - name: test that 'debug' task used default 'msg' param
18 assert:
19 that:
20 - foo.msg == "test default"
21 - local_action_foo.msg == "test default"
22
23 - name: remove test file
24 file:
25 state: absent
26
27 - name: touch test file
28 local_action:
29 module: file
30 state: touch
31
32 - name: stat test file
33 stat:
34 path: '{{ test_file }}'
35 register: foo
36
37 - name: check that test file exists
38 assert:
39 that: foo.stat.exists
40
41 - name: remove test file
42 file:
43 state: absent
44
45 - name: test that module defaults from parent are inherited and merged
46 module_defaults:
47 # Meaningless values to make sure that 'module_defaults' gets
48 # evaluated for this block
49 ping:
50 bar: baz
51 block:
52 - debug:
53 register: foo
54
55 - assert:
56 that: foo.msg == "test default"
57
58 - name: test that we can override module defaults inherited from parent
59 module_defaults:
60 debug:
61 msg: "different test message"
62 block:
63 - debug:
64 register: foo
65
66 - assert:
67 that: foo.msg == "different test message"
68
69 - name: test that module defaults inherited from parent can be removed
70 module_defaults:
71 debug: {}
72 block:
73 - debug:
74 register: foo
75
76 - assert:
77 that:
78 foo.msg == "Hello overridden world!"
79
80 - name: test that module defaults can be overridden by module params
81 block:
82 - debug:
83 msg: another test message
84 register: foo
85
86 - assert:
87 that:
88 foo.msg == "another test message"
89
90 - name: ensure that untemplate-able module_defaults breaks task templating
91 module_defaults:
92 ansible.builtin.ping:
93 data: '{{ busted_invalid_var }}'
94 ansible.builtin.ping: # debug was chosen because it ignores failures during task templating; this ensures the expected failure comes from task templating of module_defaults
95 ignore_errors: true
96 register: result
97
98 - assert:
99 that:
100 - result is failed
101 - result.msg is contains("'busted_invalid_var' is undefined")