troubleshooting

Here are the top troubleshooting and challenge-based questions specifically for Ansible, covering real-world issues you might face in your Infosys DevOps Consultant interview.


🔹 Ansible Troubleshooting Questions & Answers

1️⃣ Q: Ansible Target Unreachable ("UNREACHABLE! => Failed to connect to the host")

💡 Scenario: Your Ansible playbook fails with an unreachable error.

Answer:

  1. Check if the target server is reachable:

    ping -c 3 <target-server>
    • If the ping fails, the target machine is down or unreachable.

  2. Verify SSH access from the Ansible server:

    ssh user@target-server
    • If it fails, check if SSH service is running:

      systemctl status sshd
  3. Ensure port 22 is open on the target:

    nc -zv <target-server> 22
    • If this fails, allow SSH in the firewall:

      sudo ufw allow 22/tcp
  4. Check inventory file and ensure the correct SSH user and key are specified:

    [web_servers]
    192.168.1.10 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/ansible_id_rsa

2️⃣ Q: Ansible SSH Authentication Fails ("Permission Denied (publickey)")

💡 Scenario: Ansible fails to connect due to an SSH authentication error.

Answer:

  1. Ensure Ansible's public key is added to the target server:

  2. Verify that SSH key authentication is enabled in /etc/ssh/sshd_config:

    • If disabled, enable it:

  3. Check if the private key is correctly set in Ansible inventory:


3️⃣ Q: Ansible Playbook Fails Due to Sudo Permission Issues ("BECOME FAILED!")

💡 Scenario: Tasks that require sudo fail with a "Permission denied" error.

Answer:

  1. Ensure the user is in the sudoers list:

  2. If the user requires a password for sudo, set become_ask_pass=true:

  3. If using passwordless sudo, ensure the following is added to /etc/sudoers:


4️⃣ Q: Ansible Playbook Fails with "Undefined Variable" Error

💡 Scenario: The playbook fails due to an undefined variable.

Answer:

  1. Check if the variable is missing in the playbook:

  2. Use set_fact to define variables dynamically:

  3. Use default filter to handle missing variables:


5️⃣ Q: Ansible Playbook Runs Slowly. How to Speed It Up?

💡 Scenario: Ansible tasks are taking too long to execute.

Answer:

  1. Enable SSH Multiplexing in ansible.cfg:

  2. Use parallel execution by increasing forks:

    • Default forks value is 5, increasing it speeds up execution.

  3. Use async to run tasks in parallel:


6️⃣ Q: Ansible Playbook Fails Due to Package Manager Lock (APT/YUM Lock Issue)

💡 Scenario: Package installation fails due to another process holding the package manager lock.

Answer:

  1. For Ubuntu/Debian (APT Lock Issue):

  2. For RHEL/CentOS (YUM Lock Issue):

  3. Modify the Ansible task to retry if locked:


7️⃣ Q: How to Debug Ansible Playbook Failures?

💡 Scenario: Your playbook fails, but the error message isn’t clear.

Answer:

  1. Run playbook in verbose mode for detailed logs:

  2. Use the debug module to print variable values:

  3. Enable logging in ansible.cfg:


8️⃣ Q: Ansible Playbook Works on Some Hosts but Fails on Others

💡 Scenario: A playbook runs fine on some servers but fails on others.

Answer:

  1. Run a connectivity check:

  2. Check OS differences:

    • If OS versions differ, adjust the playbook:


9️⃣ Q: How to Prevent Ansible from Changing a Configured File if There Are No Updates?

💡 Scenario: You only want Ansible to update a file if its content changes.

Answer: Use the checksum feature:

  • This prevents unnecessary restarts if the file hasn’t changed.


🔹 Final Tips to Crack Your Infosys Interview

Explain problems using a structured approach:

  • What is the issue?

  • How do you diagnose it?

  • What is the best fix?

  • How do you prevent it in the future?

Be ready for scenario-based questions.Demonstrate troubleshooting skills with hands-on solutions.

Do you want mock interview questions or more in-depth scenarios? 🔥

Last updated