Guide 07 / 3
Ansible glossary
Decode how Ansible works and read a playbook without mixing up host, task, module and role.
Tell the control node from the managed hosts, explain idempotence and read a playbook's organisation.
01 · Understanding automation
Ansible automates technical operations by describing the expected state: it favours repeatable tasks over manual handling.
Ansible
A tool for automating and configuring systems, applications and infrastructure. It runs tasks on targets described in an inventory.
Example
Exemple métier : préparer 12 serveurs web de la même manière.
Ansible is not a container orchestrator: it complements Docker and Kubernetes.
Control node
The machine from which you run commands and playbooks. It has Ansible and the project files.
Example
Ordinateur du formateur ou VM Linux de gestion.
Managed Linux servers generally do not need the Ansible program installed.
Managed node
A server or device on which Ansible acts, often over SSH. It is described in the inventory.
Example
vm-web-01 est configurée depuis le poste de contrôle.
For Python modules, a compatible version of Python must be available on the target.
Agentless
A model where no permanent Ansible service is required on the target Linux hosts; tasks use SSH, among other things.
Example
Une connexion SSH suffit dans un cas Linux habituel.
A reachable network, valid credentials and sufficient rights are still indispensable.
Infrastructure as Code (IaC)
An approach consisting of expressing infrastructure as versioned, reproducible files.
Example
Le dépôt Git contient inventory.ini et playbooks/web.yml.
Review and validate changes like application code.
Desired state
The result to achieve on the target: package installed, file present, service started.
Example
state: present demande qu’un paquet soit installé.
Declaring the result is often more reliable than running a series of shell commands.
Idempotence
The property of a repeated operation that no longer changes the system once the requested state has been reached.
Example
Relancer « nginx installé » ne réinstalle pas nginx sans raison.
A module is idempotent depending on its function and the parameters used; “shell” is not automatically so.
Configuration management
Keeping a set of equipment in a defined configuration, despite interventions and changes.
Example
S’assurer que chrony est installé sur tous les serveurs.
02 · Inventory and connection
Before automating, you must know which machines are targeted and how Ansible reaches them.
Inventory
A file or dynamic source listing the machines and their groups, possibly with connection parameters.
Example
[web]
web1 ansible_host=192.0.2.11
web2 ansible_host=192.0.2.12
192.0.2.0/24 is an example range; replace it with the lab's IPs.
Host
An inventory entry that designates a machine and serves as an identifier in Ansible commands.
Example
web1 peut pointer vers 192.0.2.11 via ansible_host.
Group
A named set of machines for running tasks across a functional scope.
Example
[web], [db], [prod] et [lab].
Host pattern
An expression selecting the targets of a play or a command.
Example
hosts: web ; ansible web -i inventory.ini -m ping
all targets every declared target; avoid all for risky operations.
ansible_host
A variable setting the DNS name or IP used to reach a host.
Example
web1 ansible_host=192.0.2.11
ansible_user
A variable specifying the account used for the remote connection.
Example
ansible_user=deployer
This account's rights determine which operations are possible.
ansible_connection
The transport mode to the target (ssh, local, winrm depending on the environment).
Example
ansible_connection=local pour un laboratoire local.
SSH key
A key pair that lets you authenticate without sending a password on each connection.
Example
ssh -i ~/.ssh/id_ed25519 deployer@192.0.2.11
Do not store any private key in the Git repository.
group_vars / host_vars
Conventional variable folders, respectively shared by a group or specific to a host.
Example
group_vars/web.yml : http_port: 8080
A value defined in several places follows precedence rules.
Dynamic inventory
A plugin or source that automatically produces a list of machines from a cloud or a management system.
Example
Découvrir les VM d’un projet cloud sans modifier un fichier INI.
03 · Building a playbook
A playbook is a YAML scenario: it links targets, tasks and parameters. It reads from top to bottom.
Playbook
A YAML file containing a list of plays; it is the automation procedure.
Example
ansible-playbook -i inventory.ini site.yml
Play
A block that combines a selection of hosts, an execution policy and tasks.
Example
- name: Serveurs web
hosts: web
become: true
tasks: ...
Task
A named step asking Ansible to run a module with its arguments on the target.
Example
- name: Installer nginx
ansible.builtin.apt:
name: nginx
state: present
Module
An Ansible functional unit that performs an operation: package, file, service, user or API request.
Example
ansible.builtin.copy copie un fichier sur une cible.
Prefer a dedicated module to a shell command where possible.
FQCN
A module's full name with its namespace and collection, to avoid ambiguity.
Example
ansible.builtin.service plutôt que service.
Collection
A package distributing modules, plugins and sometimes roles for a particular technology.
Example
community.docker ou kubernetes.core
Some collections must be installed separately from ansible-core.
Role
A reusable folder structure that groups tasks, handlers, variables, templates and files.
Example
roles/nginx/tasks/main.yml
Useful for sharing a procedure between several projects.
Handler
A deferred task, triggered by notify when a task has reported a change.
Example
Recharger nginx seulement si sa configuration a changé.
Handlers normally run at the end of the play or on a flush.
notify
A keyword used to alert a handler following a real change.
Example
notify: Recharger nginx
become
Privilege escalation on the target, for example via sudo, to install a package or write in /etc.
Example
become: true
It does not mean “log in directly as root”.
gather_facts
A step that collects system information, enabled by default on many plays.
Example
gather_facts: true ; ansible_facts["os_family"]
04 · Variables, logic and reuse
Variables make the same playbook reusable across several groups or environments.
Variable
A name giving access to a piece of configuration data without duplicating the playbook.
Example
http_port: 8080 ; {{ http_port }}
Jinja2
A templating engine used to inject variables, expressions and conditions into files or parameters.
Example
server_name {{ site_hostname }};
Keep expressions simple; review the rendered values.
Template (.j2)
A file model transformed with the variables before being installed on the host.
Example
templates/site.conf.j2 → /etc/nginx/sites-available/site
when condition
A condition deciding whether a task should run depending on a value or on facts.
Example
when: ansible_facts["os_family"] == "Debian"
Loop (loop)
Repeats the same task over a list, without copying the YAML.
Example
loop: ["curl", "git", "htop"]
register
Stores a task's result so it can be analysed in the following tasks.
Example
register: resultat_nginx
changed / ok / failed / skipped
The states returned for each task: change made, already compliant, failure or skipped task.
Example
changed=0 lors d’une seconde exécution idempotente.
A summary with no errors does not on its own prove that the service responds correctly.
Variable precedence
Rules that determine which value wins when a variable exists in several places.
Example
Une variable -e peut écraser une variable group_vars.
Avoid defining the same parameter in several places.
05 · Control, security and operations
Useful automation must be verifiable, limited to a scope and never expose its secrets.
Check mode
A simulation estimating the changes without applying them, when the modules allow it.
Example
ansible-playbook site.yml --check
Some modules do not predict all changes: the simulation is not absolute proof.
Diff mode
Displays before/after differences for compatible modules, notably templates.
Example
ansible-playbook site.yml --check --diff
The output may contain sensitive data; protect it.
Ansible Vault
A mechanism for encrypting variables or files at rest within an Ansible project.
Example
ansible-vault encrypt group_vars/prod/vault.yml
Vault does not automatically protect secrets after they are decrypted nor in logs.
no_log
An option that hides a task's usual output, useful when it handles secrets.
Example
no_log: true
Replaces neither encryption nor proper permission management.
Least privilege
The principle of granting only the rights needed to accounts and automations.
Example
sudo uniquement pour installer les paquets requis.
Serial / rolling update
Runs the play on limited batches of machines rather than simultaneously.
Example
serial: 1 pour mettre à jour un serveur à la fois.
Plan for availability and remaining capacity before taking a node out of service.
ansible.cfg
The Ansible project's configuration file: default inventory, behaviours, paths, etc.
Example
[defaults]
inventory = inventory.ini
Check the configuration file actually loaded with ansible --version.
Ansible Galaxy
A command and repository for fetching, installing and organising collections or roles.
Example
ansible-galaxy collection install community.docker