Register Output with Ansible

From Knowledge Center
Revision as of 07:39, 3 March 2018 by Ruan (talk | contribs) (Created page with " Register the output of a command with Ansible, and write it to a debug stdout '''The Playbook:''' <pre> --- - hosts: rpi-04 user: pi tasks: - name: echo test...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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