Páginas

Saturday, 16 March 2019

Changing standard output on ansible

If you need to show the output of a command from a playbook  and you want to get it in a more human readable format, you can do it modifying your config file.
Add the following option to your configuration file /etc/ansible/ansible.cfg

stdout_callback = debug


If we try with a simple playbook

- name: show df output
   command: df -h
   register: df

 - debug:
     msg: "{{ df.stdout }}"


Before

ASK [debug] ****************************************************************************************************************************
ok: [zubi] => {
    "msg": "Filesystem      Size  Used Avail Use% Mounted on\ndevtmpfs        476M     0  476M   0% /dev\ntmpfs           493M     0  493M   0% /dev/shm\ntmpfs           493M  448K  493M   1% /run\ntmpfs           493M     0  493M   0% /sys/fs/cgroup\n/dev/xvda1      8.0G  1.2G  6.9G  15% /\ntmpfs            99M     0   99M   0% /run/user/1000"

}



After

TASK [debug] ****************************************************************************************************************************
ok: [zubi] => {}

MSG:

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        476M     0  476M   0% /dev
tmpfs           493M     0  493M   0% /dev/shm
tmpfs           493M  448K  493M   1% /run
tmpfs           493M     0  493M   0% /sys/fs/cgroup
/dev/xvda1      8.0G  1.2G  6.9G  15% /
tmpfs            99M     0   99M   0% /run/user/1000

No comments:

Post a Comment