The playbook script task will generate stdout
just like the non-playbook command, it just needs to be saved to a variable using register
. Once we've got that, the debug module can print to the playbook output stream.
tasks:
- name: Hello yourself
script: test.sh
register: hello
- name: Debug hello
debug: var=hello
- name: Debug hello.stdout as part of a string
debug: "msg=The script's stdout was `{{ hello.stdout }}`."
Output should look something like this:
TASK: [Hello yourself] ********************************************************
changed: [MyTestHost]
TASK: [Debug hello] ***********************************************************
ok: [MyTestHost] => {
"hello": {
"changed": true,
"invocation": {
"module_args": "test.sh",
"module_name": "script"
},
"rc": 0,
"stderr": "",
"stdout": "Hello World\r\n",
"stdout_lines": [
"Hello World"
]
}
}
TASK: [Debug hello.stdout as part of a string] ********************************
ok: [MyTestHost] => {
"msg": "The script's stdout was `Hello World\r\n`."
}