Introduction to Ansible
Configuration management and automation for one server or a thousand — no agents required.
Ansible automates what you’d otherwise do by hand on servers — installing packages, editing configs, restarting services — and does it consistently across many machines at once. It’s agentless (just SSH), and its files are readable YAML, which is why it’s one of the most popular configuration-management tools in DevOps.
🎯 Learning Objectives
By the end of this lesson you will:
- Understand what configuration management solves
- Explain how Ansible works and why it’s “agentless”
- Know the key Ansible concepts (control node, inventory, modules, playbooks)
- Install Ansible and verify it
The Problem Ansible Solves
Imagine setting up 20 identical web servers by hand: SSH in, install nginx, copy a config, start the service — 20 times. It’s slow, and easy to make one machine subtly different from the rest (“configuration drift”).
Ansible lets you describe the desired state once and apply it to all 20 servers automatically and repeatably.
💡 Idempotency — the key idea
Ansible tasks are idempotent: running the same playbook twice doesn’t do the work twice. If nginx is already installed, Ansible reports “ok” and moves on. You describe the end state, not the steps — so it’s safe to re-run anytime.
How Ansible Works
Control Node (your laptop / a CI runner)
│ runs ansible, holds playbooks + inventory
│ connects over SSH (no agent on targets!)
▼
Managed Nodes ──► web-01, web-02, db-01 ...- Agentless: targets need only SSH and Python — nothing to install or maintain on them. This is Ansible’s biggest advantage over agent-based tools.
- Push model: the control node pushes changes out over SSH when you run it.
Core Vocabulary
| Term | Meaning |
|---|---|
| Control node | The machine that runs Ansible |
| Managed node | A server Ansible configures (over SSH) |
| Inventory | The list of managed nodes |
| Module | A unit of work (e.g. apt, copy, service) |
| Task | A single call to a module |
| Playbook | A YAML file of tasks describing desired state |
Install Ansible
Ansible installs on the control node only:
# Ubuntu / WSL
sudo apt update && sudo apt install -y ansible
# or via pip
pip3 install ansible⚠ Nothing to install on the servers
Don’t try to install an Ansible “agent” on your target machines — there isn’t one. As long as you can SSH into a server and it has Python, Ansible can manage it.
🧪 Hands-on
Get Ansible Running
- Install Ansible on your control machine (laptop or a VM).
- Run
ansible --versionand confirm it prints a version. - In one sentence, write down why Ansible being “agentless” is useful.
- List two tasks on a server you’d want to automate with it.
🧠 Knowledge Check
What does it mean that Ansible is 'agentless'?
What does 'idempotent' mean for an Ansible task?
💼 Interview Preparation
How does Ansible differ from tools like Puppet or Chef?
Summary
You understand what Ansible is for, its agentless push model, and its core vocabulary. Next, we tell Ansible which servers to manage with an inventory, and run our first commands against them.