How to debug Ansible issues?


Sometimes, ansible doesn’t do what you want. And increasing verbosity doesn’t help. For example, I’m now trying to start coturn server, which comes with init script on systemd OS (Debian Jessie). Ansible considers it running, but it’s not. How do I look into what’s happening under the hood? Which commands are executed, and what output/exit code?


Debugging modules

  • The most basic way is to run ansible/ansible-playbook with an increased verbosity level by adding -vvv to the execution line.
  • The most thorough way for the modules written in Python (Linux/Unix) is to run ansible/ansible-playbook with an environment variable ANSIBLE_KEEP_REMOTE_FILES set to 1 (on the control machine).It causes Ansible to leave the exact copy of the Python scripts it executed (either successfully or not) on the target machine.

    The path to the scripts is printed in the Ansible log and for regular tasks they are stored under the SSH user’s home directory: ~/.ansible/tmp/.

    The exact logic is embedded in the scripts and depends on each module. Some are using Python with standard or external libraries, some are calling external commands.

Debugging playbooks

  • Similarly to debugging modules increasing verbosity level with -vvv parameter causes more data to be printed to the Ansible log
  • Since Ansible 2.1 a Playbook Debugger allows to debug interactively failed tasks: check, modify the data; re-run the task.

Debugging connections

  • Adding -vvvv parameter to the ansible/ansible-playbook call causes the log to include the debugging information for the connections.

Leave a Reply