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
    - 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: []

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

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

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