What I found to work best so far for getting CLI-like output in Ansible, and which should work out of the box (at least for me on Fedora 34, Ansible 2.9), is setting the unixy
callback for condensed Ansible output
stdout_callback = unixy
bin_ansible_callbacks = True
in your ansible.cfg
. Given the tasks
tasks:
- name: uptime
shell: uptime
- name: volumes
shell: "df -h"
the output in the terminal will look like
- all on hosts: all -
uptime...
host1 done | stdout: 08:20:09 up 33 min, 1 user, load average: 0.55, 0.27, 0.26
host2 done | stdout: 08:20:09 up 1 day, 1:39, 1 user, load average: 0.18, 0.17, 0.17
volumes...
host1 done | stdout: Filesystem Size Used Avail Use% Mounted on
/dev/root 7.2G 1.5G 5.4G 21% /overlay/pivot
devtmpfs 212M 0 212M 0% /dev
none 217M 0 217M 0% /overlay/pivot/overlay
none 217M 137M 80M 64% /overlay/rwdata
overlay 217M 137M 80M 64% /
tmpfs 217M 0 217M 0% /dev/shm
tmpfs 217M 25M 192M 12% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 217M 0 217M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 53M 200M 21% /boot
tmpfs 44M 0 44M 0% /run/user/1000
host2 done | stdout: Filesystem Size Used Avail Use% Mounted on
/dev/root 7.2G 1.5G 5.4G 22% /overlay/pivot
devtmpfs 212M 0 212M 0% /dev
none 217M 0 217M 0% /overlay/pivot/overlay
none 217M 103M 114M 48% /overlay/rwdata
overlay 217M 103M 114M 48% /
tmpfs 217M 0 217M 0% /dev/shm
tmpfs 217M 5.8M 211M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 217M 0 217M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 53M 200M 21% /boot
tmpfs 44M 0 44M 0% /run/user/1000
- Play recap -
host1 : ok=1 changed=1 unreachable=0 failed=0 rescued=0 ignored=0
host2 : ok=1 changed=1 unreachable=0 failed=0 rescued=0 ignored=0
You should be able to list all available callback plugins using ansible-doc -t callback -l
and their respective documentation using ansible-doc -t callback <plugin name>
Source Documentation