Troubleshooting
Scenario 1: Playbook Fails to Execute
Q: What do you do if a playbook fails to execute on a remote host? A:
- Check Connectivity: Ensure the control node can SSH into the target host.
- Verify Permissions: Make sure the SSH user has appropriate permissions on the target host.
- Review Error Messages: Analyze the output for specific error messages, which can indicate what went wrong.
- Ansible Configuration: Check Ansible configurations and inventory files for accuracy.
Scenario 2: Variable Undefined Error
Q: How do you resolve an "undefined variable" error in a playbook? A:
- Define Variables: Ensure all variables used are defined in the playbook, included files, or inventory.
- Typo Check: Verify there are no typos in variable names.
- Debug Module: Use the Ansible
debug
module to print variables at runtime and understand their state.
Scenario 3: Task Skipped Without Notice
** Q: Why would a task be skipped without any clear reason? A:
- Conditional Checks: Check if the task has a conditional (
when
) that is not being met. - Tags: Ensure the task isn't being excluded by the use of tags during execution.
- Dependencies: Look for any failed dependencies or
include
statements that did not execute.
Scenario 4: Slow Performance
Q: What steps can you take if Ansible is running slow? A:
- Parallelism: Increase the number of parallel forks in the Ansible configuration (
forks
setting). - Fact Gathering: Disable or limit fact gathering if not needed (
gather_facts: no
or usesetup
module selectively). - Connection Method: Switch connection methods (e.g., from SSH to paramiko) to see if performance improves.
Scenario 5: Authentication Issues
Q: How do you fix SSH authentication issues when running a playbook? A:
- SSH Keys: Ensure the control node's SSH key is authorized on the target host.
- Password Authentication: If using password authentication, verify the password is correct or use
ask_pass
to prompt for a password. - SSH Agent: If using an SSH agent, make sure it's running and loaded with the correct keys.
Scenario 6: Playbook Runs on Incorrect Hosts
** Q: What to do if a playbook is running on the wrong set of hosts? A:
- Inventory Check: Verify the inventory file to ensure host groupings are correct.
- Host Pattern: Review the playbook's host pattern to ensure it targets the intended group or host.
- Limit Option: Use the
--limit
option to restrict playbook runs to specific hosts if necessary.
By understanding and applying these troubleshooting steps, you can resolve common issues encountered while working with Ansible, ensuring a smoother automation experience.