Search code examples
ansibleansible-ad-hoc

How to format Ansible output


I want to format Ansible output from:

my_local | SUCCESS | rc=0 >>
116G

my_local2 | SUCCESS | rc=0 >>
116G

to

my_local >> 116G
my_local2 >> 116G

Is it possible?

inventory.ini:

my_local ansible_connection=local
my_local2 ansible_connection=local

Bash command:

ansible all -i inventory.ini -u root -m shell -a "df -h / | tail -1 | awk '{print \$4}'"

Solution

  • To achieve exactly what you want, you have to write your own stdout callback plugin.

    Out of the box, there is oneline stdout plugin, you can apply it with -o or --one-line flag to ansible executable to get:

    my_local | SUCCESS | rc=0 | (stdout) 116G
    my_local2 | SUCCESS | rc=0 | (stdout) 116G