Assess your skills in identifying and resolving frequent Ansible problems with these practical, scenario-based questions. Gain a deeper understanding of common configuration, syntax, environment, and connectivity issues encountered while using Ansible automation tools.
What is the most likely reason for the error 'Permission denied (publickey)' when connecting to a host using Ansible?
Explanation: A 'Permission denied (publickey)' error usually indicates Ansible cannot authenticate with the remote host because it cannot find or use the correct SSH private key. The options about the remote server not running, inventory file mistakes, and YAML syntax errors would not specifically produce this type of authentication error. Ensuring the correct key path and permissions addresses this issue.
If a playbook run fails with 'syntax error: mapping values are not allowed here', what is the most likely cause?
Explanation: YAML files are indentation sensitive, and wrong indentation commonly leads to 'mapping values are not allowed here' errors. Unsupported modules or unreachable networks do not cause YAML parsing errors. Similarly, a missing host in inventory would lead to a different error. Double-checking indentation resolves such issues.
When you receive 'UNREACHABLE!' errors for all hosts in your playbook, what is the most probable cause?
Explanation: If all hosts become unreachable, it's likely due to SSH authentication issues, such as entering wrong credentials. Issues like syntax mistakes in loops, missing group variables, or playbook version mismatches would not make hosts unreachable to Ansible but could cause task or playbook parsing failures instead.
What can cause the error 'host key verification failed' when Ansible tries to connect to a new host?
Explanation: This error arises when the connecting system has not yet recorded the remote host's key in the known_hosts file, often during first-time connections. Misspelling group names, YAML tabbing issues, or missing Python on the control node would not trigger host key verifications. Updating the known_hosts file fixes this.
If a variable is not being recognized in your playbook even though it's defined in a group_vars file, what is a likely reason?
Explanation: If the group_vars file or directory is misnamed or placed incorrectly, Ansible will not load the intended variables. Playbook syntax errors or choosing IPs versus hostnames in inventory will not affect variable loading from group_vars. While a variable value error could cause other issues, it would not prevent recognition.
Why would Ansible return the error 'ModuleNotFoundError: No module named' when running a playbook task?
Explanation: This error commonly happens when a needed Python module is not installed on the target managed host, so the module cannot be imported for the task. Duplicate inventory entries may cause warnings, but not module errors. Undefined variables and circular dependencies lead to different errors, not missing module ones.
If handlers in your playbook are never triggered, what is one possible cause?
Explanation: Handlers will only run if tasks notify them by using the 'notify' statement in task definitions. Errors such as wrong port numbers in the inventory, missing privilege escalation, or variable formatting problems can affect other playbook functions but do not directly stop handlers from being called.
What is the most likely reason for the message 'No hosts matched' when running an Ansible playbook?
Explanation: 'No hosts matched' implies that Ansible could not find the specified group or host in the inventory file. Missing tasks, using deprecated modules, or having extra blank lines would result in different errors or warnings, but would not prevent Ansible from matching hosts.
Why might Ansible display an error about 'sudo: command not found'?
Explanation: If sudo is required by your playbook but not installed on the managed host, Ansible will report that 'sudo: command not found'. YAML dictionary mistakes and handler mislabeling result in different playbook errors, and while Python version issues may cause some problems, they would not generate a sudo-related error.
A task intended to copy a file fails with a permissions error. What is a simple solution?
Explanation: Copying files to locations requiring elevated permissions may fail unless 'become: yes' is added to run the task as another user. Changing file extensions, switching handlers, or removing variables will not fix permission problems related to user privileges.