Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/callback_diy/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: Run tests
12 include_role:
13 name: callback
14 vars:
15 tests:
16 - name: Not using diy callback options
17 environment:
18 ANSIBLE_NOCOLOR: 'true'
19 ANSIBLE_FORCE_COLOR: 'false'
20 ANSIBLE_STDOUT_CALLBACK: community.general.diy
21 playbook: |
22 - hosts: testhost
23 gather_facts: false
24 tasks:
25 - name: Sample task name
26 debug:
27 msg: sample debug msg
28 expected_output:
29 - ""
30 - "PLAY [testhost] ****************************************************************"
31 - ""
32 - "TASK [Sample task name] ********************************************************"
33 - "ok: [testhost] => {"
34 - " \"msg\": \"sample debug msg\""
35 - "}"
36 - ""
37 - "PLAY RECAP *********************************************************************"
38 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
39
40 - name: Set playbook_on_start_msg callback using environment variable
41 environment:
42 ANSIBLE_NOCOLOR: 'true'
43 ANSIBLE_FORCE_COLOR: 'false'
44 ANSIBLE_STDOUT_CALLBACK: community.general.diy
45 ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_START_MSG: "Sample output Sample playbook message"
46 playbook: |
47 - hosts: testhost
48 gather_facts: false
49 tasks:
50 - name: Sample task name
51 debug:
52 msg: sample debug msg
53 expected_output:
54 - "Sample output Sample playbook message"
55 - ""
56 - "PLAY [testhost] ****************************************************************"
57 - ""
58 - "TASK [Sample task name] ********************************************************"
59 - "ok: [testhost] => {"
60 - " \"msg\": \"sample debug msg\""
61 - "}"
62 - ""
63 - "PLAY RECAP *********************************************************************"
64 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
65
66 - name: Set playbook_on_play_start_msg callback using play variable
67 environment:
68 ANSIBLE_NOCOLOR: 'true'
69 ANSIBLE_FORCE_COLOR: 'false'
70 ANSIBLE_STDOUT_CALLBACK: community.general.diy
71 playbook: !unsafe |
72 - name: Sample play name
73 hosts: testhost
74 gather_facts: false
75 vars:
76 ansible_callback_diy_playbook_on_play_start_msg: Sample output {{ ansible_callback_diy.play.name }}
77 tasks:
78 - name: Sample task name
79 debug:
80 msg: sample debug msg
81 expected_output:
82 - "Sample output Sample play name"
83 - ""
84 - "TASK [Sample task name] ********************************************************"
85 - "ok: [testhost] => {"
86 - " \"msg\": \"sample debug msg\""
87 - "}"
88 - ""
89 - "PLAY RECAP *********************************************************************"
90 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
91
92 - name: Set playbook_on_task_start_msg callback using play variable
93 environment:
94 ANSIBLE_NOCOLOR: 'true'
95 ANSIBLE_FORCE_COLOR: 'false'
96 ANSIBLE_STDOUT_CALLBACK: community.general.diy
97 playbook: !unsafe |
98 - hosts: testhost
99 gather_facts: false
100 vars:
101 ansible_callback_diy_playbook_on_task_start_msg: Sample output {{ ansible_callback_diy.task.name }}
102 tasks:
103 - name: Sample task name
104 debug:
105 msg: sample debug msg
106 expected_output:
107 - ""
108 - "PLAY [testhost] ****************************************************************"
109 - "Sample output Sample task name"
110 - "ok: [testhost] => {"
111 - " \"msg\": \"sample debug msg\""
112 - "}"
113 - ""
114 - "PLAY RECAP *********************************************************************"
115 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
116
117 - name: Set playbook_on_task_start_msg callback using task variable
118 environment:
119 ANSIBLE_NOCOLOR: 'true'
120 ANSIBLE_FORCE_COLOR: 'false'
121 ANSIBLE_STDOUT_CALLBACK: community.general.diy
122 playbook: !unsafe |
123 - hosts: testhost
124 gather_facts: false
125 tasks:
126 - name: Sample task name
127 debug:
128 msg: sample debug msg
129 vars:
130 ansible_callback_diy_playbook_on_task_start_msg: Sample output {{ ansible_callback_diy.task.name }}
131 expected_output:
132 - ""
133 - "PLAY [testhost] ****************************************************************"
134 - "Sample output Sample task name"
135 - "ok: [testhost] => {"
136 - " \"msg\": \"sample debug msg\""
137 - "}"
138 - ""
139 - "PLAY RECAP *********************************************************************"
140 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
141
142 - name: Set runner_on_ok_msg callback using task variable
143 environment:
144 ANSIBLE_NOCOLOR: 'true'
145 ANSIBLE_FORCE_COLOR: 'false'
146 ANSIBLE_STDOUT_CALLBACK: community.general.diy
147 playbook: !unsafe |
148 - hosts: testhost
149 gather_facts: false
150 tasks:
151 - name: Sample task name
152 debug:
153 msg: sample debug msg
154 vars:
155 ansible_callback_diy_runner_on_ok_msg: Sample output {{ ansible_callback_diy.result.output.msg }}
156 expected_output:
157 - ""
158 - "PLAY [testhost] ****************************************************************"
159 - ""
160 - "TASK [Sample task name] ********************************************************"
161 - "Sample output sample debug msg"
162 - ""
163 - "PLAY RECAP *********************************************************************"
164 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
165
166 - name: Set runner_on_failed_msg callback using task variable
167 environment:
168 ANSIBLE_NOCOLOR: 'true'
169 ANSIBLE_FORCE_COLOR: 'false'
170 ANSIBLE_STDOUT_CALLBACK: community.general.diy
171 playbook: |
172 - hosts: testhost
173 gather_facts: false
174 tasks:
175 - name: Sample task name
176 debug:
177 msg: sample debug msg
178 failed_when: true
179 ignore_errors: true
180 vars:
181 ansible_callback_diy_runner_on_failed_msg: Sample output Sample failure message
182 expected_output:
183 - ""
184 - "PLAY [testhost] ****************************************************************"
185 - ""
186 - "TASK [Sample task name] ********************************************************"
187 - "Sample output Sample failure message"
188 - ""
189 - "PLAY RECAP *********************************************************************"
190 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1 "
191
192 - name: Set runner_on_skipped_msg callback using task variable
193 environment:
194 ANSIBLE_NOCOLOR: 'true'
195 ANSIBLE_FORCE_COLOR: 'false'
196 ANSIBLE_STDOUT_CALLBACK: community.general.diy
197 playbook: !unsafe |
198 - hosts: testhost
199 gather_facts: false
200 tasks:
201 - name: Sample task name
202 debug:
203 msg: sample debug msg
204 when: false
205 vars:
206 ansible_callback_diy_runner_on_skipped_msg: Sample output Skipped {{ ansible_callback_diy.task.name }}
207 expected_output:
208 - ""
209 - "PLAY [testhost] ****************************************************************"
210 - ""
211 - "TASK [Sample task name] ********************************************************"
212 - "Sample output Skipped Sample task name"
213 - ""
214 - "PLAY RECAP *********************************************************************"
215 - "testhost : ok=0 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 "
216
217 - name: Set runner_item_on_ok_msg callback using task variable
218 environment:
219 ANSIBLE_NOCOLOR: 'true'
220 ANSIBLE_FORCE_COLOR: 'false'
221 ANSIBLE_STDOUT_CALLBACK: community.general.diy
222 playbook: !unsafe |
223 - hosts: testhost
224 gather_facts: false
225 tasks:
226 - name: Sample task name
227 debug:
228 msg: sample debug msg {{ item }}
229 loop:
230 - sample item 1
231 - sample item 2
232 - sample item 3
233 vars:
234 ansible_callback_diy_runner_item_on_ok_msg: Sample output Looping {{ ansible_callback_diy.result.output.msg }}
235 expected_output:
236 - ""
237 - "PLAY [testhost] ****************************************************************"
238 - ""
239 - "TASK [Sample task name] ********************************************************"
240 - "Sample output Looping sample debug msg sample item 1"
241 - "Sample output Looping sample debug msg sample item 2"
242 - "Sample output Looping sample debug msg sample item 3"
243 - ""
244 - "PLAY RECAP *********************************************************************"
245 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
246
247 - name: Set runner_item_on_failed_msg callback using task variable
248 environment:
249 ANSIBLE_NOCOLOR: 'true'
250 ANSIBLE_FORCE_COLOR: 'false'
251 ANSIBLE_STDOUT_CALLBACK: community.general.diy
252 playbook: !unsafe |
253 - hosts: testhost
254 gather_facts: false
255 tasks:
256 - name: Sample task name
257 debug:
258 msg: sample debug msg {{ item }}
259 loop:
260 - sample item 1
261 - sample item 2
262 - sample item 3
263 failed_when: item == 'sample item 2'
264 ignore_errors: true
265 vars:
266 ansible_callback_diy_runner_item_on_failed_msg: Sample output Looping sample failure message
267 expected_output:
268 - ""
269 - "PLAY [testhost] ****************************************************************"
270 - ""
271 - "TASK [Sample task name] ********************************************************"
272 - "ok: [testhost] => (item=sample item 1) => {"
273 - " \"msg\": \"sample debug msg sample item 1\""
274 - "}"
275 - "Sample output Looping sample failure message"
276 - "ok: [testhost] => (item=sample item 3) => {"
277 - " \"msg\": \"sample debug msg sample item 3\""
278 - "}"
279 - # Apparently a bug was fixed in Ansible, as before it ran through with "All items completed"
280 - "fatal: [testhost]: FAILED! => {\"msg\": \"All items completed\"}"
281 - "fatal: [testhost]: FAILED! => {\"msg\": \"One or more items failed\"}"
282 - "...ignoring"
283 - ""
284 - "PLAY RECAP *********************************************************************"
285 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1 "
286
287 - name: Set runner_item_on_skipped_msg callback using task variable
288 environment:
289 ANSIBLE_NOCOLOR: 'true'
290 ANSIBLE_FORCE_COLOR: 'false'
291 ANSIBLE_STDOUT_CALLBACK: community.general.diy
292 playbook: !unsafe |
293 - hosts: testhost
294 gather_facts: false
295 tasks:
296 - name: Sample task name
297 debug:
298 msg: sample debug msg {{ item }}
299 loop:
300 - sample item 1
301 - sample item 2
302 - sample item 3
303 when: item != 'sample item 2'
304 vars:
305 ansible_callback_diy_runner_item_on_skipped_msg: Sample output Looping Skipped {{ ansible_callback_diy.result.output.item }}
306 expected_output:
307 - ""
308 - "PLAY [testhost] ****************************************************************"
309 - ""
310 - "TASK [Sample task name] ********************************************************"
311 - "ok: [testhost] => (item=sample item 1) => {"
312 - " \"msg\": \"sample debug msg sample item 1\""
313 - "}"
314 - "Sample output Looping Skipped sample item 2"
315 - "ok: [testhost] => (item=sample item 3) => {"
316 - " \"msg\": \"sample debug msg sample item 3\""
317 - "}"
318 - ""
319 - "PLAY RECAP *********************************************************************"
320 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
321
322 - name: Set playbook_on_stats_msg callback using play variable
323 environment:
324 ANSIBLE_NOCOLOR: 'true'
325 ANSIBLE_FORCE_COLOR: 'false'
326 ANSIBLE_STDOUT_CALLBACK: community.general.diy
327 playbook: !unsafe |
328 - hosts: testhost
329 gather_facts: false
330 vars:
331 ansible_callback_diy_playbook_on_stats_msg: |+2
332 Sample output stats
333 ===============================
334 {% for key in ansible_callback_diy.stats | sort %}
335 {% set color_one = "" %}
336 {% set color_two = "" %}
337 {% if ansible_callback_diy.stats[key] %}
338 {% if key == 'ok' %}
339 {% set prefix = ' ' %}
340 {% set suffix = ' ' %}
341 {% elif key == 'changed' %}
342 {% set prefix = ' ' %}
343 {% set suffix = ' ' %}
344 {% elif key == 'processed' %}
345 {% set prefix = ' ' %}
346 {% set suffix = ' ' %}
347 {% elif key == 'skipped' %}
348 {% set prefix = ' ' %}
349 {% set suffix = ' ' %}
350 {% else %}
351 {% set prefix = "" %}
352 {% set suffix = "" %}
353 {% endif %}
354 {{ color_one }}{{ "%s%s%s" | format(prefix,key,suffix) }}{{ color_two }}: {{ ansible_callback_diy.stats[key] | to_nice_yaml }}
355 {% endif %}
356 {% endfor %}
357 tasks:
358 - name: Sample task name
359 debug:
360 msg: sample debug msg
361 expected_output:
362 - ""
363 - "PLAY [testhost] ****************************************************************"
364 - ""
365 - "TASK [Sample task name] ********************************************************"
366 - "ok: [testhost] => {"
367 - " \"msg\": \"sample debug msg\""
368 - "}"
369 - " Sample output stats"
370 - "==============================="
371 - " ok : testhost: 1"
372 - ""
373 - " processed : testhost: 1"
374
375 - name: Suppress output on playbook_on_task_start_msg callback using task variable
376 environment:
377 ANSIBLE_NOCOLOR: 'true'
378 ANSIBLE_FORCE_COLOR: 'false'
379 ANSIBLE_STDOUT_CALLBACK: community.general.diy
380 playbook: |
381 - hosts: testhost
382 gather_facts: false
383 tasks:
384 - name: Sample task name
385 debug:
386 msg: sample debug msg
387 vars:
388 ansible_callback_diy_playbook_on_task_start_msg: ''
389 expected_output:
390 - ""
391 - "PLAY [testhost] ****************************************************************"
392 - "ok: [testhost] => {"
393 - " \"msg\": \"sample debug msg\""
394 - "}"
395 - ""
396 - "PLAY RECAP *********************************************************************"
397 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
398
399 - name: Suppress output on runner_on_ok_msg callback using task variable
400 environment:
401 ANSIBLE_NOCOLOR: 'true'
402 ANSIBLE_FORCE_COLOR: 'false'
403 ANSIBLE_STDOUT_CALLBACK: community.general.diy
404 playbook: |
405 - hosts: testhost
406 gather_facts: false
407 tasks:
408 - name: Sample task name
409 debug:
410 msg: sample debug msg
411 vars:
412 ansible_callback_diy_runner_on_ok_msg: ''
413 expected_output:
414 - ""
415 - "PLAY [testhost] ****************************************************************"
416 - ""
417 - "TASK [Sample task name] ********************************************************"
418 - ""
419 - "PLAY RECAP *********************************************************************"
420 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
421
422 - name: Set runner_on_ok_msg_color using task variable
423 environment:
424 ANSIBLE_NOCOLOR: 'true'
425 ANSIBLE_FORCE_COLOR: 'false'
426 ANSIBLE_STDOUT_CALLBACK: community.general.diy
427 playbook: !unsafe |
428 - hosts: testhost
429 gather_facts: false
430 tasks:
431 - name: Sample task name
432 debug:
433 msg: sample debug msg
434 vars:
435 ansible_callback_diy_runner_on_ok_msg: Sample output {{ ansible_callback_diy.result.output.msg }}
436 ansible_callback_diy_runner_on_ok_msg_color: blue
437 expected_output:
438 - ""
439 - "PLAY [testhost] ****************************************************************"
440 - ""
441 - "TASK [Sample task name] ********************************************************"
442 - "Sample output sample debug msg"
443 - ""
444 - "PLAY RECAP *********************************************************************"
445 - "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
446
447 - name: Set on_any_msg
448 environment:
449 ANSIBLE_NOCOLOR: 'true'
450 ANSIBLE_FORCE_COLOR: 'false'
451 ANSIBLE_STDOUT_CALLBACK: community.general.diy
452 ANSIBLE_CALLBACK_DIY_ON_ANY_MSG: foo
453 playbook: !unsafe |
454 - hosts: testhost
455 gather_facts: false
456 tasks:
457 - name: A loop
458 debug:
459 msg: "{{ item }}"
460 loop:
461 - 1
462 - 2
463 - name: Sample task name
464 debug:
465 msg: sample debug msg
466 - name: Skipped task
467 command: ls /
468 when: false
469 expected_output:
470 - "foo"
471 - ""
472 - "PLAY [testhost] ****************************************************************"
473 - "foo"
474 - ""
475 - "TASK [A loop] ******************************************************************"
476 - "foo"
477 - "foo"
478 - "ok: [testhost] => (item=1) => {"
479 - " \"msg\": 1"
480 - "}"
481 - "foo"
482 - "ok: [testhost] => (item=2) => {"
483 - " \"msg\": 2"
484 - "}"
485 - "foo"
486 - "foo"
487 - ""
488 - "TASK [Sample task name] ********************************************************"
489 - "foo"
490 - "foo"
491 - "ok: [testhost] => {"
492 - " \"msg\": \"sample debug msg\""
493 - "}"
494 - "foo"
495 - ""
496 - "TASK [Skipped task] ************************************************************"
497 - "foo"
498 - "foo"
499 - "skipping: [testhost]"
500 - "foo"
501 - ""
502 - "PLAY RECAP *********************************************************************"
503 - "testhost : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 "
504 - ""
505 - "foo"