Debian Codegraph @

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

raw
1 - name: Run a module which returns a warning and deprecation warning
2 noisy:
3 register: result
4
5 - name: Verify the registered module results can be displayed without error
6 debug:
7 var: result
8
9 - include_tasks: plugin_errors.yml
10
11 - command: echo {% raw %}{{ foo }}{% endraw %}
12 register: result
13
14 - assert:
15 that:
16 - result.stdout_lines|first == expected
17 vars:
18 expected: !unsafe '{{ foo }}'
19
20 - name: Assert that templating treats strings that look like Python as strings (previously some conversions would apply)
21 assert:
22 that:
23 - foo | type_debug == 'str'
24 - |
25 foo == '{"null": null, "true": true, "false": false}'
26 vars:
27 foo: '{{ "" }}{"null": null, "true": true, "false": false}'
28
29 - name: Ensure that valid Jinja builtin test plugin works even when its name is an invalid Ansible plugin name (1/2)
30 set_fact:
31 foo: '{{ [{"failed": false}] | selectattr("failed", "==", true) }}'
32
33 - name: Ensure that a non-existent test plugin that is also an invalid Ansible plugin name fails properly (2/2)
34 raw: echo {{ [{}] | selectattr("failed", "asdf ", true) }}
35 ignore_errors: true
36 register: result
37
38 - assert:
39 that:
40 - result is failed
41 - result.msg is contains("No test named 'asdf '")
42
43 - name: Ensure that runtime dispatch errors result in a failure
44 debug:
45 msg: "{{ lookup('vars', 'v1', default='', default='') }}"
46 ignore_errors: true
47 register: r
48
49 - assert:
50 that:
51 - r is failed
52 - "'keyword argument repeated' in r.msg"
53
54 - name: ensure nested indirect templating is lazy (only recurse to render containers with templated when one is leaving the template system)
55 vars:
56 tripwire_file: "{{ output_dir ~ '/bang' }}"
57 top_level: '{{ intermediate }}'
58 intermediate: '{{ lowest }}'
59 lowest:
60 key1: static data
61 key2:
62 subdict2:
63 unused_value_with_tripwire: '{{ lookup("pipe", "touch " ~ output_dir ~ "/bang") }}'
64 block:
65 - name: ensure tripwire file is missing
66 raw: rm -f {{ tripwire_file }}
67
68 - name: manipulate a var with nested indirected templates and ensure that only the areas we access are templated
69 set_fact:
70 am_i_lazy: '{{ top_level.key1 }}'
71
72 - name: check presence of tripwire
73 stat:
74 path: '{{ tripwire_file }}'
75 register: stat_res
76
77 - assert:
78 that:
79 - am_i_lazy == "static data"
80 - not stat_res.stat.exists
81
82 # omitting output for brevity in CI
83 - no_log: true
84 block:
85 - name: ensure that `hostvars` gets flattened properly from Templar
86 debug:
87 msg: '{{ hostvars }}'
88 register: hostvars_result
89
90 - name: ensure that `hostvars['somehost']` gets flattened properly from Templar
91 debug:
92 msg: '{{ hostvars.testhost }}'
93 register: hostvarsvars_result
94
95 - name: ensure that `vars` gets flattened properly from Templar
96 debug:
97 msg: '{{ vars }}'
98 register: vars_result
99
100 - assert:
101 that:
102 - hostvars_result.msg.testhost.inventory_hostname == "testhost"
103 - hostvars_result.msg | type_debug == "dict"
104 - hostvarsvars_result.msg.inventory_hostname == "testhost"
105 - hostvarsvars_result.msg | type_debug == "dict"
106 - vars_result.msg.hostvars is defined
107 - vars_result.msg | type_debug == "dict"
108
109 - vars:
110 task_scalar: i am a scalar
111 task_dict_yaml:
112 scalar_ref: '{{ task_scalar }}'
113 task_dict_jinja: '{{ {"scalar_ref": task_scalar} }}'
114 task_list_yaml: [ '{{ task_scalar }}' ]
115 task_list_jinja: '{{ [ task_scalar ] }}'
116 block:
117 - name: ensure that lazy containers with embedded templates handle equality-ish operators correctly
118 assert:
119 that:
120 - 'task_dict_yaml == {"scalar_ref": "i am a scalar"}'
121 - 'task_dict_jinja == {"scalar_ref": "i am a scalar"}'
122 - task_list_yaml == ["i am a scalar"]
123 - task_list_jinja == ["i am a scalar"]
124
125 - name: trigger a template cycle that overflows the stack
126 vars:
127 cycle: '{{ cycle }}'
128 raw: echo {{ cycle }}
129 ignore_errors: true
130 register: result
131
132 - assert:
133 that:
134 - result is failed
135 - result.msg is contains("Recursive loop detected in template")
136
137 - raw: "{{ 'x' in y }}"
138 ignore_errors: yes
139 register: error
140
141 - name: check that proper error message is emitted when in operator is used
142 assert:
143 that: "\"'y' is undefined\" in error.msg"
144
145 - name: test inline list containing a constant template arg to a lookup
146 debug:
147 msg: |-
148 {{ lookup('list', ['{{ 1 }}']) }}
149 register: result
150 failed_when: result.msg != [1]
151
152 - name: test inline dict containing a constant template arg to a lookup
153 debug:
154 msg: |-
155 {{ lookup('dict', {'key': '{{ 1 }}'}) }}
156 register: result
157 failed_when: result.msg.value != 1
158
159 - name: test inline constant template arg to a lookup in a non-optimizable expression
160 vars:
161 echo_me: hi mom
162 debug:
163 msg: |-
164 {{ lookup('pipe', 'echo "{{ echo_me }}"') }}
165 register: result
166 failed_when: result.msg != "hi mom"
167
168 - name: ensure that embedded template constants are ignored outside conditionals and lookup args
169 raw: echo {{ "{{ 1 }}" }}
170 register: result
171 failed_when: result.stdout is not contains "{"
172
173 - name: ensure that embedded template constants in locals work in lookup args
174 debug:
175 msg: |-
176 {{ lookup('pipe', 'echo {{ "h" + "i" | string }}') }}
177 register: result
178
179 - name: ensure that embedded template constants in locals are ignored outside conditionals and lookups
180 raw: |-
181 echo "{% set a = '{{ 1 }}' %}{% set b = '{{ 2 }}' %}{{ a + b }}"
182 register: result
183 failed_when: result.stdout is not contains("{")
184
185 - name: ensure that embedded template constants in locals do not work in conditional-as-template fallback (pre-2.17 compat)
186 assert:
187 that: |-
188 {% set a = '{{ 1 }}' %}
189 {% set b = '{{ 2 }}' %}
190 {{ a + b == ("{" ~ "{ 1 }}{" ~ "{ 2 }}") }}
191 register: result
192
193 - name: ensure that embedded non-string templates fail
194 raw: echo {{ {{ 1 }} }}
195 register: result
196 ignore_errors: true
197
198 - assert:
199 that:
200 - result is failed
201 - result.msg is contains("Syntax error")
202
203 - vars:
204 dict_with_undecryptable_vault:
205 deeper:
206 vaulted_thing: !vault |
207 $ANSIBLE_VAULT;1.1;AES256
208 63326561376261613563313535363635306336343061343735343931396538666263326333316135
209 3364323839336665663238376238336661636630316635360a613537653337363035373261623038
210 30633437653432623936376239376466316434393134393632313163633965353530376361626564
211 3262633163333464330a393161353063326562626665333138373839633165376639343166333561
212 3663
213 block:
214 - name: undecryptable vault values in a scalar template should trip on JSON serialization
215 debug:
216 msg: '{{ dict_with_undecryptable_vault | to_json }}'
217 ignore_errors: true
218 register: result
219
220 - assert:
221 that:
222 - result is failed
223 - result.msg is contains("undecryptable variable")
224
225 - name: undecryptable vault values in a list of templates should trip on JSON serialization
226 debug:
227 msg:
228 - '{{ dict_with_undecryptable_vault | to_json }}'
229 ignore_errors: true
230 register: result
231
232 - assert:
233 that:
234 - result is failed
235 - result.msg is contains("undecryptable variable")
236
237 - name: vaulted values are not trusted for templating
238 vars:
239 # value is {{ "not trusted" }} encrypted with "blarblar"
240 vaulted_with_template: !vault |
241 $ANSIBLE_VAULT;1.1;AES256
242 36306639316132393663356162643765396231396462623962373832643539306635356639366633
243 6234303731383636623165633330653435336130613361370a373931613335353762376433636263
244 35363536613933396532636430646337393932393166396133613666386433353932373063356235
245 3666336365616535610a636534333332633930326331353533626332363263363666373730386264
246 31643561353465613030343632663036313963363634663231393665316437646530
247 decrypt_vaulted_value: '{{ vaulted_with_template | unvault("blarblar") }}'
248 debug:
249 var: decrypt_vaulted_value
250 register: vault_value_untrusted
251
252 - assert:
253 that:
254 - vault_value_untrusted.decrypt_vaulted_value == ('{' ~ '{ "not trusted" }}')