Introduction
What Ansible is, why configuration management exists, the core vocabulary from inventory to handlers, and how Ansible fits with Terraform, Docker and Jenkins.
A server is only as useful as the software and settings on it. The hard part has never been installing Java once. It is installing the same version, with the same settings, on every server, every time, and still knowing six months later exactly how each machine was built.
Ansible answers that with a simple idea: describe the state you want in a text file, and let a tool make every server match it. That file can be reviewed, versioned in Git and re-run safely, which is something no admin's memory can offer.
What Ansible is
Ansible is an open source automation tool for configuration management, application deployment and orchestration. It is sponsored by Red Hat, written in Python, and driven by YAML files called playbooks.
Three properties make it popular:
| Property | What it means for you |
|---|---|
| Agentless | Nothing to install on the servers. Ansible connects over SSH and needs only Python on the other side |
| Readable | Playbooks are YAML. Someone who has never used Ansible can still read what a playbook does |
| Idempotent | Most modules check before they act, so running a playbook again changes only what is different |
Core vocabulary
| Term | Meaning |
|---|---|
| Control node | The machine with Ansible installed, where you run ansible and ansible-playbook |
| Managed node | A server that Ansible configures. It does not need Ansible installed |
| Inventory | The list of managed nodes, organised into groups such as webservers and dbservers |
| Module | A small program that does one job: ansible.builtin.copy, ansible.builtin.dnf, ansible.builtin.service |
| Task | One call to a module with its arguments, plus a name |
| Play | A set of tasks mapped to a set of hosts |
| Playbook | A YAML file with one or more plays |
| Ad hoc command | A single module run from the command line, without a playbook |
| Facts | Information Ansible gathers about each host (OS, IPs, memory) before running tasks |
| Variable | A named value used in tasks, set in the playbook, inventory or on the command line |
| Vault | Ansible's tool for encrypting files and values that hold secrets |
| Handler | A task that runs only when another task notifies it of a change |
| Tag | A label on a task, used to run or skip it from the command line |
| Collection | A package of modules and plugins. The built-in ones live in ansible.builtin |
How a run works
When you run a playbook, Ansible reads the inventory to find the hosts, connects to each one over SSH, copies the module for the current task, runs it with the host's Python, collects the JSON result (ok, changed or failed) and moves on. It works on several hosts in parallel, so ten servers take about as long as one.
Where Ansible fits
Ansible usually sits between infrastructure and application:
| Tool | Job | Relation to Ansible |
|---|---|---|
| Terraform | Provisioning: creates EC2 instances, VPCs, security groups | Creates the machines that Ansible then configures |
| Ansible | Configuration: packages, files, users, services | The subject of this course |
| Docker | Packages the application with its runtime | Ansible can install Docker and start containers on servers |
| Kubernetes | Runs containers at scale | Configures itself declaratively, so Ansible is used less inside the cluster |
| Jenkins | CI/CD pipelines | Can run ansible-playbook as a pipeline stage after a build |
Ansible can also create cloud resources, and Terraform can run scripts on servers. In practice, most teams let each tool do what it does best: Terraform for infrastructure, Ansible for what goes on it.
What this course builds
Everything happens on one small lab on AWS: a control node and two managed nodes, one in the webservers group and one in the dbservers group. On that lab you write the playbooks a DevOps engineer writes in the first weeks of a job: creating files, installing Git, Java and Maven, deploying a website with Apache httpd, then improving those playbooks with variables, encrypted secrets, handlers and tags.
Versions used in this course
The lecture installs Ansible with pip on Amazon Linux 2023, which gives ansible 8.7 with ansible-core 2.15 (the newest release that supports the system's Python 3.9). The current release at the time of writing is ansible-core 2.21, which needs Python 3.12 or newer on the control node. Every playbook in this course works on both. Where newer versions behave differently, the lesson says so.
Start with Ansible Introduction.
Official references
Written By: Shramik Masti
How is this guide?
Last updated on
Getting Started
A roadmap for the Ansible course, from the configuration management problem to a working AWS lab, ad hoc commands, playbooks, variables, Vault, handlers and tags.
Ansible Introduction
Understand why configuring many servers by hand breaks down, what configuration management means, and where Ansible fits as an open source automation tool.
