Skip to content
$ lynuxpro
← Ansible

LESSON 1 OF 17 · BEGINNER · 9 MIN

Configuration management and Ansible

Free previewLesson 1 of the 2 free lessons in this Pro course.Unlock all 17

HOW IT WORKSBy hand versus Ansible

Typing on each serverslow, differentPlaybookthe rule bookAnsibleServer 1Server 2Server 3
1/5

Setting up servers by hand is slow, and each one ends up a little different.

In simple words

  • Configuration management: setting up and keeping many servers in the right state (packages, files, services) automatically from code.
  • Ansible: a configuration management tool that connects over SSH and runs tasks written in YAML.
  • Agentless: nothing extra has to be installed on the servers. Ansible just needs SSH and Python.
  • Idempotent: running it again changes nothing if the server is already right.

Big picture

Think of a restaurant chain. Every kitchen must have the same oven settings, the same menu and the same cleaning rules. You could walk to each kitchen and set things up by hand. Or you could write one rule book and send it to every kitchen. Configuration management is the rule book for servers. Ansible is the tool that reads the rule book and makes each server match it.

The problem with doing it by hand

  • You log in to a server and type commands. Next month nobody remembers what you typed.
  • Server 1 and server 2 end up slightly different. People call this configuration drift.
  • Setting up 50 servers takes 50 times as long.
  • A broken server is hard to rebuild the same way.

What Ansible is

Ansible is a free tool that configures servers from text files. You describe the state you want, and Ansible makes it true.

WordPlain meaning
Control nodeThe machine where you run Ansible (your laptop or a CI server)
Managed nodeA server that Ansible configures
InventoryThe list of managed nodes
ModuleA small tool for one job, like installing a package
TaskOne call to a module
PlaybookA YAML file with a list of tasks for some servers

Agentless

Many older tools need a program (an agent) installed on every server. Ansible does not. It connects over SSH (or WinRM for Windows), copies a small script, runs it, and removes it. The only thing a server needs is SSH and Python.

Idempotent: safe to run again

A good Ansible task says "make sure nginx is installed", not "install nginx". If it is already installed, Ansible does nothing. This property is called idempotence. It means you can run a playbook ten times and get the same result.

Ansible and other tools

ToolMain jobStyle
AnsibleConfigure servers and run tasksAgentless, YAML
TerraformCreate cloud resourcesDeclarative, state file
Puppet and ChefConfigure serversAgent on each server, own languages

A common pattern: Terraform creates the servers, then Ansible configures them.

How one run works

  1. You run ansible-playbook on the control node.
  2. Ansible reads the inventory to learn which servers to use.
  3. It connects to each server over SSH.
  4. For each task, it copies the module to the server and runs it.
  5. The module checks the current state and changes only what is wrong.
  6. Ansible removes the module and prints the result.

Files you will meet

File or folderWhat it holds
ansible.cfgsettings for Ansible
inventory.inithe list of servers
site.ymla playbook
group_vars/ and host_vars/variables for groups and single servers
roles/reusable packages of tasks

Install it

python3 -m pip install --user ansibleansible --version
SHELLbashutf-8 · 2L
ansible [core 2.17.4]  config file = None  python version = 3.12.4
OUTPUTterminalutf-8 · 3L

Try your first command. It runs on your own machine, so it needs no inventory:

ansible localhost -m ansible.builtin.ping
SHELLbashutf-8 · 1L
localhost | SUCCESS => {    "changed": false,    "ping": "pong"}
OUTPUTterminalutf-8 · 4L

If you see pong, Ansible and Python both work.

Common mistakes

  • Thinking Ansible needs an agent. It does not.
  • Writing shell commands for everything. Use a module when one exists, because modules are idempotent.
  • Forgetting that Python must exist on the managed node.

Summary

  • Configuration management keeps many servers the same, from one rule book.
  • Ansible is agentless: SSH in, run, leave.
  • Playbooks are YAML files of tasks. Tasks are safe to repeat.

CHECK YOUR UNDERSTANDING

3 quick questions

  1. 1. What does 'agentless' mean for Ansible?

  2. 2. What does idempotent mean?

  3. 3. Which pairing is most common?