Register Output with Ansible

From Knowledge Center
Jump to: navigation, search

Register the output of a command with Ansible, and write it to a debug stdout

The Playbook:

---
- hosts: rpi-04
  user: pi
  tasks:
    - name: echo test
      command: "echo ruan"
      register: echo_output

    - debug: msg="{{echo_output.stdout}}"

Test Run:

 $ ansible-playbook -i hosts ap_echo.yml

PLAY [rpi-04] *****************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.1.118]

TASK: [echo test] *************************************************************
changed: [192.168.1.118]

TASK: [debug msg="{{echo_output.stdout}}"] ************************************
ok: [192.168.1.118] => {
    "msg": "ruan"
}

PLAY RECAP ********************************************************************
192.168.1.118              : ok=3    changed=1    unreachable=0    failed=0