Scenario
🔹 Ansible Scenario-Based Questions & Answers
1️⃣ Q: You need to copy files from one target server to another using Ansible. How will you do it?
Approach:
Ansible Playbook:
- name: Copy file from one target to another
hosts: server1
tasks:
- name: Fetch the file from server1
fetch:
src: /etc/myapp/config.yaml
dest: /tmp/config.yaml
flat: yes # To avoid creating extra directories
- name: Copy file to server2
hosts: server2
tasks:
- name: Transfer the file to server2
copy:
src: /tmp/config.yaml
dest: /etc/myapp/config.yaml
owner: root
group: root
mode: '0644'Alternative: Use synchronize (if SSH connectivity exists between servers)
synchronize (if SSH connectivity exists between servers)2️⃣ Q: How do you ensure only one Ansible playbook execution at a time?
Approach:
Ansible Playbook:
3️⃣ Q: How do you run a playbook only if a specific service is running?
Ansible Playbook:
4️⃣ Q: You need to rollback an Ansible deployment. How would you handle it?
Ansible Playbook with Rollback Strategy:
5️⃣ Q: How do you manage secrets in Ansible securely?
Steps to Secure Secrets:
6️⃣ Q: How do you ensure idempotency in Ansible playbooks?
Example: Installing Nginx (Idempotent Approach)
🔹 Key Takeaways to Crack Your Infosys DevOps Consultant Interview
🔹 More Ansible Scenario-Based Interview Questions & Answers (Short & Precise)
1️⃣ Q: How do you handle dynamic inventories in Ansible?
2️⃣ Q: How do you run only specific tasks in a playbook?
3️⃣ Q: How do you execute a playbook in a dry run mode?
4️⃣ Q: How do you handle errors in Ansible?
5️⃣ Q: How do you pass variables to an Ansible playbook?
6️⃣ Q: How do you run an Ansible task as a different user?
7️⃣ Q: How do you handle dependencies between tasks?
8️⃣ Q: How do you fetch logs from multiple servers using Ansible?
9️⃣ Q: How do you make Ansible run in parallel across multiple servers?
🔟 Q: How do you check if a file exists before performing an action?
1️⃣1️⃣ Q: How do you limit execution to a single server in an inventory group?
1️⃣2️⃣ Q: How do you remove sensitive data from Ansible output?
1️⃣3️⃣ Q: How do you troubleshoot when Ansible can't reach a target server?
1️⃣4️⃣ Q: How do you run an Ansible playbook only on a specific OS?
1️⃣5️⃣ Q: How do you ensure a task runs only once in a multi-node setup?
1️⃣6️⃣ Q: How do you handle large file transfers in Ansible?
1️⃣7️⃣ Q: How do you reboot a server and wait for it to come back up?
1️⃣8️⃣ Q: How do you execute only specific tasks from a playbook?
1️⃣9️⃣ Q: How do you execute a playbook on a subset of inventory?
2️⃣0️⃣ Q: How do you update all packages on a server using Ansible?
🔥 Final Tips for Your Infosys DevOps Consultant Interview
Last updated