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:
Check if the target server is reachable:
Copy ping -c 3 < target-serve r > If the ping fails, the target machine is down or unreachable.
Verify SSH access from the Ansible server:
Copy ssh user@target-server If it fails, check if SSH service is running:
Copy systemctl status sshd Ensure port 22 is open on the target:
Copy nc -zv < target-serve r > 22 If this fails, allow SSH in the firewall:
Copy sudo ufw allow 22/tcp Check inventory file and ensure the correct SSH user and key are specified:
Copy [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:
Ensure Ansible's public key is added to the target server:
Verify that SSH key authentication is enabled in /etc/ssh/sshd_config :
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:
Ensure the user is in the sudoers list:
If the user requires a password for sudo, set become_ask_pass=true :
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:
Check if the variable is missing in the playbook:
Use set_fact to define variables dynamically:
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:
Enable SSH Multiplexing in ansible.cfg :
Use parallel execution by increasing forks:
Default forks value is 5, increasing it speeds up execution.
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:
For Ubuntu/Debian (APT Lock Issue):
For RHEL/CentOS (YUM Lock Issue):
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:
Run playbook in verbose mode for detailed logs:
Use the debug module to print variable values:
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:
Run a connectivity check:
Check OS differences:
If OS versions differ, adjust the playbook:
💡 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:
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 11 months ago