G
GuideDevOps
Lesson 14 of 14

Troubleshooting & Debugging

Part of the Ansible tutorial series.

Overview

Debugging is a crucial skill when working with automation. Ansible provides several tools to help identify and fix issues in your playbooks.

Verbose Mode

The most common way to debug playbooks is by increasing the verbosity.

  • -v: Verbose
  • -vv: More verbose
  • -vvv: Debug connection issues
  • -vvvv: Debug connection and module execution

Example: Run with -vvv

ansible-playbook site.yml -vvv

Expected Result:

Using /etc/ansible/ansible.cfg as config file
...
<192.168.1.10> ESTABLISH SSH CONNECTION FOR USER: vagrant
<192.168.1.10> SSH: EXEC ssh -C -o ControlMaster=auto ...

Debugger Keyword

You can use the debugger keyword to interactively debug a task that failed.

Example: Debugger on Failure

- name: This task might fail
  command: /bin/false
  debugger: on_failed

Expected Result: When the task fails, Ansible will open an interactive shell where you can inspect variables and re-run the task.

fatal: [192.168.1.10]: FAILED! => {"changed": false, "cmd": "/bin/false", ...}
[192.168.1.10] TASK: This task might fail ****************************
(debug)