How do I see stdout for ansible-playbook commands? -v only shows ansible output, not the individual commands. It would be great if I could figure out how to do this immediately, so if something fails or hangs I can see why.
e.g.
- name: print to stdout
action: command echo "hello"
would print
TASK: [print variable] ********************************************************
hello
I think you can register the result to a variable, then print with debug.
Instead of stdout I would suggest using stdout_lines. For multiline output this is much nicer, e.g.
gives
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.
I found using the minimal
stdout_callback
with ansible-playbook gave similar output to using ad-hoc ansible.In your ansible.cfg (Note that I'm on OS X so modify the
callback_plugins
path to suit your install)So that a task such as this
Gives output like this, like an ad-hoc command would
I'm using ansible-playbook 2.2.1.0
If you really want to watch the output in realtime, there is a hacky way around it, at least for the ansible
shell
module.In whatever shell script wraps your call to ansible, touch and tail a log file in a background job. Then redirect the ansible shell command's output to append to that log file. You need to make sure you kill the background tail job after ansible finishes, or it will be left dangling.
For example, in a bash script that calls ansible:
Then in some ansible role:
I've found that just killing a stuck process on the remote via ssh gives back the stdout. I find thats shorter than writing workarounds that won't be used in the final playbook anyways:
kill -9 PID