What is Ansible?
Learn what Ansible is for DevOps interviews — agentless configuration management, playbooks, idempotency, with examples and MCQs.
Expected Interview Answer
Ansible is an open-source, agentless configuration management and automation tool that connects to remote machines over SSH and applies tasks written in human-readable YAML playbooks to install software, configure systems, and orchestrate multi-step deployments.
Unlike tools that require an installed agent on every managed node, Ansible pushes changes over standard SSH, using Python on the target to execute modules idempotently — meaning running the same playbook twice produces the same result without duplicating effects. Playbooks describe a sequence of tasks against groups of hosts defined in an inventory file, such as installing a package, copying a config file, or restarting a service. Because it has no agents to install and maintain, Ansible has a lower operational footprint than agent-based alternatives, and its YAML syntax makes playbooks readable even to those who did not write them. It is commonly used alongside provisioning tools like Terraform, where Terraform creates the infrastructure and Ansible configures the software running on it.
- Agentless — only requires SSH access, nothing to install on targets
- Idempotent tasks make re-running playbooks safe
- Human-readable YAML playbooks are easy to review
- Works well alongside provisioning tools like Terraform
AI Mentor Explanation
Ansible is like a touring coach who does not need to live permanently at every venue but instead visits each ground with a written checklist — set the pitch length, mark the creases, prepare the nets — and applies it consistently everywhere the team plays. The coach carries no special equipment installed at each venue in advance; they simply arrive, follow the checklist, and leave the ground correctly prepared, and running the same checklist twice does not cause any harm. This visit-and-configure-without-installing-anything-permanent approach is exactly how Ansible manages remote servers over SSH.
Step-by-Step Explanation
Step 1
Define inventory
List target hosts and group them, such as "webservers" or "databases," in an inventory file.
Step 2
Write a playbook
Describe a sequence of tasks in YAML, such as installing a package or copying a config file.
Step 3
Connect over SSH
Ansible connects to each target host over SSH, requiring no pre-installed agent.
Step 4
Execute idempotent tasks
Each task runs a module that only makes changes if the current state differs from the desired state.
What Interviewer Expects
- Understanding that Ansible is agentless and SSH-based
- Awareness of idempotency and why it matters for safe re-runs
- Knowledge of playbooks, inventories, and modules as core concepts
- Ability to contrast Ansible’s configuration role with Terraform’s provisioning role
Common Mistakes
- Confusing Ansible with a provisioning tool like Terraform
- Believing Ansible requires an agent installed on every managed node
- Not understanding idempotency and why re-running a playbook is safe
- Assuming playbooks must be run in an imperative, one-off style rather than declaratively
Best Answer (HR Friendly)
“Ansible is an automation tool that configures servers by connecting over SSH and running a checklist of tasks written in plain YAML. It needs no special software installed on the servers themselves, and running the same checklist twice is always safe.”
Code Example
- name: Configure web servers
hosts: webservers
become: true
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- name: Start nginx service
service:
name: nginx
state: started
enabled: trueFollow-up Questions
- What does it mean for an Ansible task to be idempotent?
- How does Ansible differ from Terraform in a typical DevOps workflow?
- How does Ansible connect to managed hosts without an agent?
- How would you organize playbooks for a large, multi-team infrastructure?
MCQ Practice
1. How does Ansible typically connect to managed hosts?
Ansible is agentless and connects over SSH, executing modules via Python already present on most targets.
2. What does idempotency mean for an Ansible task?
Idempotent tasks check current state and only act if it differs from the desired state, making re-runs safe.
3. How do Ansible and Terraform typically work together?
A common pattern is Terraform creating the infrastructure and Ansible handling post-provisioning configuration.
Flash Cards
What is Ansible? — An agentless, SSH-based configuration management and automation tool using YAML playbooks.
What does agentless mean for Ansible? — No special software needs to be pre-installed on managed hosts; it connects via existing SSH access.
What is idempotency in Ansible tasks? — Re-running a task produces the same result without duplicating effects.
How do Ansible and Terraform typically pair together? — Terraform provisions infrastructure; Ansible configures the software running on it.