How to see stdout of ansible commands?
Solution 1:
I think you can register the result to a variable, then print with debug.
- name: print to stdout
command: echo "hello"
register: hello
- debug: msg="{{ hello.stdout }}"
- debug: msg="{{ hello.stderr }}"
Solution 2:
Instead of stdout I would suggest using stdout_lines. For multiline output this is much nicer, e.g.
- hosts: all
tasks:
- name: Run ls.sh and output "ls /"
script: ls.sh
register: out
- debug: var=out.stdout_lines
gives
TASK: [debug var=out.stdout_lines] ********************************************
ok: [local] => {
"var": {
"out.stdout_lines": [
"total 61",
"lrwxrwxrwx 1 root root 7 Feb 15 2015 bin -> usr/bin",
"drwxr-xr-x 6 root root 1024 Aug 24 22:08 boot",
"drwxr-xr-x 22 root root 3580 Sep 8 18:41 dev",
[...]
"drwxr-xr-x 9 root root 4096 Aug 25 19:14 usr",
"drwxr-xr-x 13 root root 4096 Feb 25 2015 var"
]
}
}
Regarding real time output for debugging purposes there is a closed bug report https://github.com/ansible/ansible/issues/3887#issuecomment-54672569 discussing the reasons why this is not possible and will not be implemented.