How to view the Unix command that Ansible runs? How to view the Unix command that Ansible runs? unix unix

How to view the Unix command that Ansible runs?


Ansible uses Python scripts to perform its actions (it might call external programs from the Python, but if there is no necessity, it doesn't).

You can cause Ansible to leave the actual script which was run on the target machine by adding ANSIBLE_KEEP_REMOTE_FILES=1 to the environment on the control machine before executing ansible-playbook.

For example if you run:

ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook playbook.yml -vvv

You will see in the transcript something like:

PUT /var/folders/nw/2vnhg_gj77v_cyfv0p1vdfj80000gn/T/tmpidULyi TO /home/vagrant/.ansible/tmp/ansible-tmp-1484137690.32-255077767492235/mount.py

Then if you open the mount.py you can verify the actual code (you might also be able to re-run it).


No, you can't see the command without source code modification.

mount module's source code suggests that it:

  • write '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n' to fstab
  • execute mount <name>


Have you tried running ansible with the -vvvv flag? That enables verbosity, and it usually shows you what command is being run.

It is usually hidden somewhere in the output, but it is there.