Troubleshooting Common Ansible Issues Quiz Quiz

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.

  1. Question 1

    What is the most likely reason for the error 'Permission denied (publickey)' when connecting to a host using Ansible?

    1. The remote server is not running.
    2. The inventory file path is misspelled.
    3. The playbook contains a YAML syntax error.
    4. The SSH private key is missing or incorrectly specified.

    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.

  2. Question 2

    If a playbook run fails with 'syntax error: mapping values are not allowed here', what is the most likely cause?

    1. Unsupported Ansible module used.
    2. Missing host in the inventory file.
    3. Network unreachable from Ansible control node.
    4. Incorrect indentation in the YAML file.

    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.

  3. Question 3

    When you receive 'UNREACHABLE!' errors for all hosts in your playbook, what is the most probable cause?

    1. Incorrect SSH credentials provided.
    2. Syntax mistake in a loop construct.
    3. Version mismatch in playbook file.
    4. A missing variable in group_vars.

    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.

  4. Question 4

    What can cause the error 'host key verification failed' when Ansible tries to connect to a new host?

    1. Inventory group is misspelled.
    2. Ansible is missing Python on the control node.
    3. YAML file uses tabs instead of spaces.
    4. The host's SSH key is not in the known_hosts file.

    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.

  5. Question 5

    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?

    1. The inventory file uses IP addresses instead of hostnames.
    2. The filename or directory in group_vars is incorrect.
    3. The playbook has a syntax error in a task.
    4. The YAML variable value has an extra colon.

    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.

  6. Question 6

    Why would Ansible return the error 'ModuleNotFoundError: No module named' when running a playbook task?

    1. Role dependency is circular.
    2. Required Python module is missing on the managed host.
    3. Inventory file lists duplicate entries.
    4. Playbook variables are not defined.

    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.

  7. Question 7

    If handlers in your playbook are never triggered, what is one possible cause?

    1. The playbook lacks the 'become' keyword.
    2. Variables are passed in the wrong format.
    3. Tasks are not using the 'notify' directive.
    4. The inventory file uses incorrect port numbers.

    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.

  8. Question 8

    What is the most likely reason for the message 'No hosts matched' when running an Ansible playbook?

    1. There is a missing 'tasks' entry in the playbook.
    2. The inventory file does not contain the group or host specified.
    3. A module used in the playbook is deprecated.
    4. There is an extra blank line in the 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.

  9. Question 9

    Why might Ansible display an error about 'sudo: command not found'?

    1. Handlers are misnamed in the playbook.
    2. A YAML dictionary is missing a key.
    3. The managed host does not have the sudo package installed.
    4. The control node is using the wrong Python version.

    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.

  10. Question 10

    A task intended to copy a file fails with a permissions error. What is a simple solution?

    1. Use a different Ansible handler.
    2. Add 'become: yes' to the task.
    3. Remove all variables from the playbook.
    4. Change the file extension in the task.

    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.