Home › Interview questions › Ansible
Ansible Interview Questions & Answers
69 Ansible interview questions in 4 levels — junior to senior, plus 16 production scenarios. Read 3 free answers with real-world analogies.
Free sample answers
What is Ansible, and what problem does configuration management actually solve?
One-liner
Ansible is a tool that automates setting up and configuring servers, so you describe the desired setup once and apply it consistently across many machines, instead of manually configuring each one by hand.
Real-world analogy
It's like a standardized set of instructions handed to every single store in a chain, ensuring every location is set up exactly the same way, rather than each store manager configuring things their own individual way based on personal preference.
Detailed explanation
- Without configuration management, setting up a new server usually means manually running a long list of commands, which is slow and genuinely easy to get slightly wrong or inconsistent between different machines.
- Ansible lets you write down the desired configuration once, in a file, and apply it to as many servers as needed, guaranteeing every single one ends up configured identically.
- Because the configuration is written down, it's also naturally documented and version-controllable, unlike a series of manual commands someone ran once and never actually wrote down anywhere.
Scenario
A team manually configures each new server by SSHing in and running the same list of setup commands from memory, and small inconsistencies creep in over time depending on who actually did the setup. Writing an Ansible playbook that describes the exact desired configuration means every new server is now set up identically, regardless of who actually runs it.
Best practices
- Write down your server configuration as an Ansible playbook rather than relying on manual commands run from memory.
- Store your playbooks in version control, just like application code, so changes are tracked over time.
- Start with automating your most frequently repeated manual setup task first, rather than trying to automate everything at once.
What are block and rescue used for in Ansible, and how do they actually relate to error handling?
One-liner
A block groups several tasks together, and a rescue section lets you define what should actually happen if any task within that block genuinely fails, similar in spirit to a try-catch pattern in a regular programming language.
Real-world analogy
It's like a specific backup plan for a defined sequence of steps — if anything within that particular sequence genuinely goes wrong, a separate, specific recovery plan actually kicks in, rather than the entire overall process just stopping cold with no graceful, planned response.
Detailed explanation
- Tasks inside a block run in the normal, standard sequence, and if any one of them genuinely fails, Ansible immediately stops that block and moves directly to the corresponding rescue section instead.
- The rescue section can perform genuinely useful recovery actions, like logging the actual specific failure or attempting an alternative fallback approach, rather than the entire playbook simply failing outright with no graceful handling at all.
- An optional always section runs regardless of whether the block genuinely succeeded or failed, useful for a genuinely necessary cleanup step that should always happen either way.
Scenario
A team's playbook attempts a risky operation that occasionally genuinely fails for a specific, known reason, and without any error handling, the entire playbook run simply stops abruptly at that exact point. Wrapping the risky task in a block with a corresponding rescue section that handles the specific known failure gracefully lets the rest of the playbook continue running normally instead of stopping cold.
Best practices
- Use block and rescue for a genuinely known, specific failure mode you actually want to handle gracefully.
- Use the always section for cleanup that genuinely needs to happen regardless of whether the block actually succeeded or failed.
- Avoid using rescue to silently hide a genuine, unexpected failure you should actually be investigating instead.
A playbook run fails to connect to a large number of hosts at once with SSH-related errors, though these hosts were reachable just yesterday. How do you troubleshoot it?
One-liner
Check for a genuinely common, shared cause first — like an expired SSH key, a changed network configuration, or an updated security group — since a large number of hosts failing simultaneously usually points to something they all genuinely share, rather than many completely unrelated individual problems.
Real-world analogy
It's like multiple, seemingly unrelated neighborhoods all losing phone service at roughly the exact same time — you wouldn't investigate each individual house separately first; you'd immediately look for what they all actually genuinely share.
Detailed explanation
- Checking whether an SSH key was recently rotated or expired, without every relevant host actually being updated with the corresponding new key, is a very common real cause of this kind of sudden, widespread failure.
- Checking for a recent network or firewall change — like an updated security group rule that now inadvertently blocks the specific outbound SSH traffic your control machine actually needs — is another likely, common cause.
- Testing SSH connectivity manually to just one single affected host, outside of Ansible entirely, quickly confirms whether the underlying actual issue is genuinely a network or credential problem, rather than something specific to Ansible itself.
Scenario
A playbook run suddenly fails to connect to nearly every single host in the inventory, and manually testing SSH to one specific affected host confirms the connection itself is genuinely being refused. Investigating further reveals a recent security group change accidentally blocked the specific SSH port from the control machine's own IP range. Correcting the security group rule resolves the connectivity failures across every affected host at once.
Best practices
- Look for a genuinely common, shared cause when many hosts fail simultaneously, rather than investigating each one separately in isolation.
- Test connectivity manually, outside of Ansible, to quickly confirm whether the underlying issue is genuinely network or credential related.
- Check for a recent, related change (a key rotation, a security group update) as your first, likely suspect.
A preview of the 69 questions in the Ansible guide
Junior (20)
- What is Ansible, and what problem does configuration management actually solve?
- Why is Ansible described as agentless, and what does that actually mean in practice?
- What is an inventory in Ansible, and what does a basic one actually look like?
- What does a basic Ansible playbook actually look like, and what are its main parts?
+ 16 more Junior questions, with full answers, in the guide.
Mid-level (19)
- What is a dynamic inventory, and why would a team actually need one instead of a simple static file?
- How does Ansible's variable precedence actually work, and why does it matter when the exact same variable is defined in more than one place?
- How do conditionals work in Ansible using the when clause, and what's a common practical use for one?
- What is Ansible Vault, and what specific problem does it actually solve for handling sensitive data?
+ 15 more Mid-level questions, with full answers, in the guide.
Senior (14)
- How would you design a role and repository structure for Ansible at a large organization with many teams and many different environments?
- How would you scale Ansible to reliably manage thousands of hosts, beyond just increasing the fork count?
- How would you design a secrets management strategy for Ansible at an organizational scale, beyond just using Ansible Vault for a single project?
- How would you set up a CI/CD pipeline for testing and linting Ansible playbooks before they're actually allowed to merge?
+ 10 more Senior questions, with full answers, in the guide.
Scenario (16)
- Running the exact same playbook twice produces a genuinely different result the second time, even though nothing about the actual target hosts should have changed. How do you investigate?
- A playbook run fails to connect to a large number of hosts at once with SSH-related errors, though these hosts were reachable just yesterday. How do you troubleshoot it?
- A handler you expected to run after a configuration change genuinely never actually fires. How do you debug it?
- A task uses a variable that ends up with a completely different, unexpected value than what you actually defined in your role's defaults file. How do you figure out where the wrong value is actually coming from?
+ 12 more Scenario questions, with full answers, in the guide.
Get the full DevOps / SRE Interview Guide