Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


- name: print to stdout
  action: command echo "hello"

would print

TASK: [print variable] ******************************************************** 

share|improve this question
related:… – barraponto Feb 12 '15 at 22:08

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 }}"
share|improve this answer
Thanks @bfschott, that worked. – Sathish Dec 19 '13 at 12:38
Additionally, you can debug a variable directly with - debug: var=hello. Sometimes this is more helpful for multiline output or Ansible module output (rather than command/shell output). – geerlingguy Mar 8 '14 at 3:03
I had trouble getting Java output using this. The fix is to redirect all of Java's output to stdout: shell: java -version 2>&1 – Matthias Braun Jan 6 '15 at 17:27
that's a lot better nothing, but you only get the stdout message after the command has successfully completed. I was having an issue where ansible would appear to hang. The reason was that I was using the wrong username for an rsync command, which spooled the interactive password request, which just hanged ansible. It was very difficult to debug - but if I could see stdout in realtime, I would have immediately realised what I'd done wrong. I would LOVE this functionality, if possible. – Michael B Feb 9 '15 at 4:31
while this works, it means ansible makes debugging really hard. Let's imagine the first task never terminates (perhaps it is foolishly waiting for user input)... the user would never know! Moreover, the register module, or whatever it is doesn't produce objects that have the stdout or stderr variable set.... so it's really bad that we don't just get the output by default :| – vlad-ardelean Jul 10 '15 at 10:47

Instead of stdout I would suggest using stdout_lines. For multiline output this is much nicer, e.g.

- hosts: all
    - name: Run and output "ls /"
      register: out

    - debug: var=out.stdout_lines


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 discussing the reasons why this is not possible and will not be implemented.

share|improve this answer
+1 for linking the "real time output" bug. – ntc2 Nov 26 '15 at 0:29

protected by Michael Hampton Jul 25 at 19:21

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.