Skip to content

Ansible Overview

First PublishedLast UpdatedByAtif Alam

Ansible is an open-source automation tool for configuration management, application deployment, and orchestration. It connects to machines over SSH (or WinRM for Windows), runs tasks, and requires no agent on the target hosts — just Python and SSH.

  • Repeatable — Define the desired state of your servers once, apply it everywhere.
  • Drift prevention — Re-run the same playbook and it corrects any manual changes.
  • Self-documenting — Playbooks describe exactly what’s installed and configured.
  • Scalable — Configure 1 server or 1,000 with the same code.
  • Agentless — No daemon to install or maintain on target hosts. Just SSH + Python.
  • Simple syntax — YAML playbooks are readable even by non-developers.
  • Idempotent — Running the same playbook twice produces the same result (no unintended side effects).
  • Batteries included — Thousands of built-in modules for packages, files, services, users, cloud APIs, containers, and more.
  • Push-based — You run Ansible from a control node and it pushes changes. No pull agent polling.
ToolApproachAgentLanguage
AnsiblePush, agentlessNone (SSH)YAML (playbooks)
ChefPull, agent-basedYesRuby (recipes) — see Chef overview
PuppetPull, agent-basedYesPuppet DSL (manifests)
SaltStackPush or pullOptional (minion)YAML + Jinja2

They solve different problems and are often used together:

TerraformAnsible
PurposeProvision infrastructure (create VMs, networks, databases)Configure infrastructure (install packages, deploy apps, manage files)
StateTracks state in a state fileStateless — checks current state each run
ApproachDeclarativeProcedural (tasks run in order) with declarative modules
Typical flowTerraform creates the VMs → Ansible configures them
Control node (your laptop / CI server)
│ SSH
├──────→ Host 1 (web server)
├──────→ Host 2 (web server)
└──────→ Host 3 (database)
1. Ansible reads the inventory (which hosts to target)
2. Reads the playbook (what tasks to run)
3. Connects via SSH
4. Copies a small Python script to each host
5. Executes the script (the module)
6. Collects results and reports back
7. Cleans up the script

No persistent connection, no agent process. Each run is independent.

  • Control node — The machine where you run Ansible (your laptop, a CI server).
  • Managed node (host) — A remote machine Ansible configures.
  • Inventory — A list of managed nodes, organized into groups.
  • Playbook — A YAML file containing plays (sets of tasks to run on hosts).
  • Task — A single action (install a package, copy a file, start a service).
  • Module — The code that performs a task (e.g. apt, copy, service). Ansible ships with thousands.
  • Role — A reusable, structured package of tasks, templates, files, and variables.
  • Handler — A task triggered by a notification (e.g. restart nginx after config changes).
  • Facts — System information Ansible gathers from hosts (OS, IP, memory, etc.).
Terminal window
# pip (recommended)
pip install ansible
# macOS
brew install ansible
# Ubuntu/Debian
sudo apt install ansible

Verify:

Terminal window
ansible --version

Start with inventory (which hosts), then playbooks (what to do), then modules, roles, and best practices.

  • Inventory — Static and dynamic inventory, groups, host variables, and children.
  • Playbooks — Plays, tasks, handlers, conditionals, loops, error handling, rolling updates, delegation, async, and strategies.
  • Modules — Common modules for packages, files, services, users, commands, and writing custom modules.
  • Roles — Role structure, creating roles, Ansible Galaxy, and dependencies.
  • Variables and Templates — Variable precedence, facts, Jinja2 templates, filters, and conditionals.
  • Best Practices — Idempotency, tagging, Vault, Molecule, project layout, troubleshooting, and performance tuning.