| 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: community.general.print_task is not enabled |
| 17 |
environment: |
| 18 |
ANSIBLE_NOCOLOR: 'true' |
| 19 |
ANSIBLE_FORCE_COLOR: 'false' |
| 20 |
playbook: | |
| 21 |
- hosts: testhost |
| 22 |
gather_facts: false |
| 23 |
tasks: |
| 24 |
- name: Sample task |
| 25 |
debug: |
| 26 |
msg: This is a test |
| 27 |
expected_output: |
| 28 |
- "" |
| 29 |
- "PLAY [testhost] ****************************************************************" |
| 30 |
- "" |
| 31 |
- "TASK [Sample task] *************************************************************" |
| 32 |
- "ok: [testhost] => {" |
| 33 |
- " \"msg\": \"This is a test\"" |
| 34 |
- "}" |
| 35 |
- "" |
| 36 |
- "PLAY RECAP *********************************************************************" |
| 37 |
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 " |
| 38 |
|
| 39 |
- name: community.general.print_task is enabled |
| 40 |
environment: |
| 41 |
ANSIBLE_NOCOLOR: 'true' |
| 42 |
ANSIBLE_FORCE_COLOR: 'false' |
| 43 |
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task' |
| 44 |
playbook: | |
| 45 |
- hosts: testhost |
| 46 |
gather_facts: false |
| 47 |
tasks: |
| 48 |
- name: Sample task |
| 49 |
debug: |
| 50 |
msg: This is a test |
| 51 |
expected_output: |
| 52 |
- "" |
| 53 |
- "PLAY [testhost] ****************************************************************" |
| 54 |
- "" |
| 55 |
- "TASK [Sample task] *************************************************************" |
| 56 |
- "" |
| 57 |
- "- name: Sample task" |
| 58 |
- " debug:" |
| 59 |
- " msg: This is a test" |
| 60 |
- "" |
| 61 |
- "ok: [testhost] => {" |
| 62 |
- " \"msg\": \"This is a test\"" |
| 63 |
- "}" |
| 64 |
- "" |
| 65 |
- "PLAY RECAP *********************************************************************" |
| 66 |
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 " |
| 67 |
|
| 68 |
- name: Print with msg parameter on the same line |
| 69 |
environment: |
| 70 |
ANSIBLE_NOCOLOR: 'true' |
| 71 |
ANSIBLE_FORCE_COLOR: 'false' |
| 72 |
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task' |
| 73 |
playbook: | |
| 74 |
- hosts: testhost |
| 75 |
gather_facts: false |
| 76 |
tasks: |
| 77 |
- name: Sample task |
| 78 |
debug: msg="This is a test" |
| 79 |
expected_output: |
| 80 |
- "" |
| 81 |
- "PLAY [testhost] ****************************************************************" |
| 82 |
- "" |
| 83 |
- "TASK [Sample task] *************************************************************" |
| 84 |
- "" |
| 85 |
- "- name: Sample task" |
| 86 |
- " debug: msg=\"This is a test\"" |
| 87 |
- "" |
| 88 |
- "ok: [testhost] => {" |
| 89 |
- " \"msg\": \"This is a test\"" |
| 90 |
- "}" |
| 91 |
- "" |
| 92 |
- "PLAY RECAP *********************************************************************" |
| 93 |
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 " |
| 94 |
|
| 95 |
- name: Task with additional parameters |
| 96 |
environment: |
| 97 |
ANSIBLE_NOCOLOR: 'true' |
| 98 |
ANSIBLE_FORCE_COLOR: 'false' |
| 99 |
ANSIBLE_CALLBACKS_ENABLED: 'community.general.print_task' |
| 100 |
playbook: | |
| 101 |
- hosts: testhost |
| 102 |
gather_facts: false |
| 103 |
tasks: |
| 104 |
- name: Sample task |
| 105 |
when: True |
| 106 |
vars: |
| 107 |
test_var: "Hello World" |
| 108 |
debug: |
| 109 |
var: test_var |
| 110 |
expected_output: |
| 111 |
- "" |
| 112 |
- "PLAY [testhost] ****************************************************************" |
| 113 |
- "" |
| 114 |
- "TASK [Sample task] *************************************************************" |
| 115 |
- "" |
| 116 |
- "- name: Sample task" |
| 117 |
- " when: true" |
| 118 |
- " vars:" |
| 119 |
- " test_var: Hello World" |
| 120 |
- " debug:" |
| 121 |
- " var: test_var" |
| 122 |
- "" |
| 123 |
- "ok: [testhost] => {" |
| 124 |
- " \"test_var\": \"Hello World\"" |
| 125 |
- "}" |
| 126 |
- "" |
| 127 |
- "PLAY RECAP *********************************************************************" |
| 128 |
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 " |