FreeKB - debug module (printing output to the console)
Ansible - debug module (printing output to the console)

The debug module can be used to print output.  In this example, "Hello World" will be printed.

- debug: 
    msg: "Hello World"

 

When the play is run, the following should be produced.

TASK [debug]
ok: [server1.example.com] => {
    "msg": "Hello World"
}

 

Often, debug is used along with the register module. In this example, the stdout/stderr/rc of the ls (list) command will be stored in a variable named "out". 

- name: list command
  shell: "ls /tmp"
  register: out

 

You can then printing the output using the debug module, like this.

- name: standard out
  debug: 
    msg: "{{ out.stdout_lines }}"

- name: standard error
  debug: 
    msg: "{{ out.stderr_lines }}"

- name: return code
  debug: 
    msg: "{{ out.rc }}"

 

Running this playbook should return the following. In this example, standard out returns a file or directory in the /tmp directory named "foo", there was no standard error, and the return code is 0 (success).

TASK [list command]
ok: [server1.example.com]

TASK [standard out]
ok: [server1.example.com] => {
    "msg": "foo"
}

TASK [standard error]
ok: [server1.example.com] => {
    "msg": ""
}

TASK [return code]
ok: [server1.example.com] => {
    "msg": "0"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter f65ff in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |