Troubleshooting
Even well‑written playbooks can fail. Knowing how to troubleshoot Ansible runs saves time. This chapter covers common errors and techniques to debug.
Increase Verbosity
The
-v (verbose) flag gives more output. Use multiple v’s for more detail:ansible-playbook playbook.yml -vvv # shows SSH output
ansible-playbook playbook.yml -vvvv # extreme debuggingCheck Mode and Diff
Run in check mode to see what would change without actually applying changes:
ansible-playbook playbook.yml --check --diff--diff shows file differences for template and copy modules.Debug Module
Print variable values or messages during execution:
- name: Print variable value
debug:
var: ansible_os_family
- name: Print custom message
debug:
msg: "The target OS is {{ ansible_os_family }}"Syntax Check
Validate YAML syntax without executing:
ansible-playbook playbook.yml --syntax-checkTesting with a Single Host
Limit execution to one host to isolate issues:
ansible-playbook playbook.yml --limit web1Common Errors and Fixes
- Authentication failure: Check SSH keys,
ansible_user, and--ask-passor--ask-become-pass. - Module not found: Verify module name spelling; use
ansible-doc -lto list. - YAML indentation: Use spaces, not tabs; run
--syntax-check. - Permission denied: Add
become: yesand ensure sudo rights. - Variable undefined: Use
default()filter or ensure variable is defined invarsor inventory.
Logging
Enable logging to a file by setting in
ansible.cfg or environment variable:export ANSIBLE_LOG_PATH=~/ansible.logTwo Minute Drill
- Use
-vvvfor verbose output,--check --difffor dry run. - Debug module prints variables and messages.
- Validate syntax with
--syntax-check. - Limit execution to a single host with
--limit. - Common issues: authentication, permissions, indentation, undefined variables.
Need more clarification?
Drop us an email at career@quipoinfotech.com
