Using Ansible 2.11.6 from Ubuntu. I have two Raspberry Pis in inventory
. One is an older Pi3 with Stretch; the other a Pi4 with Buster.
$ ansible -i inventory -m shell -a "df -h" all
shows the result of df -h
for both Pis, as expected. But
$ ansible-playbook -i inventory main.yml
where main.yml
is
---
- hosts: all
tasks:
- name: show disk space
shell:
cmd: df -h
after gathering facts, shows
TASK [show disk space] *******************
changed: [pi4]
changed: [pi3]
without showing the output of df -h
.
I've tried command:
instead of shell:
. I've tried executable: /bin/bash
. No difference. The same main.yml
works with a Vagrant ansible provisioner when building an Ubuntu VM, and shows df -h
output.
What am I missing?
Update This was a mistake on my end. The Vagrantfile template I'd been using included ansible.verbose = true
. Remove that, and everything behaves consistently.
Best Answer
At the default verbosity task results are not shown by the
default
stdout callback. Ad hoc commands normally use theminimal
callback, which has different behaviour. If you are seeing it in the Vagrant output it is either using a different callback or running with a higher verbosity, where more information is displayed:You can also explicitly output things using
debug
: