Ansible playbook shell output


I would like to quickly monitor some hosts using commands like ps,dstat etc using ansible-playbook. The ansible command itself perfectly does what I want, for instance I’d use:

and it nicely prints all std output for every host like this:

However this requires me to keep a bunch of shell scripts around for every task which is not very ‘ansible’ so I put this in a playbook:

and run it with -vv, but the output baiscally shows the dictionary content and newlines are not printed as such so this results in an unreadable mess like this:

I also tried adding register: var and the a ‘debug’ task to show {{ var.stdout }} but the result is of course the same.

Is there a way to get nicely formatted output from a command’s stdout/stderr when run via a playbook? I can think of a number of possible ways (format output using sed? redirect output to file on the host then get that file back and echo it to the screen?), but with my limited knowledge of the shell/ansible it would take me a day to just try it out.


The debug module could really use some love, but at the moment the best you can do is use this:

It gives an output like this:

Leave a Reply