Ansible Playbook Basics
A playbook is a YAML file containing a list of plays, and a play is a list of tasks aimed at a pattern of hosts. This writes one with four tasks, runs the two checks worth running first, executes it, runs it again to see every task report ok, and finishes by breaking the YAML on purpose so the parser error is recognisable.
Plays and Playbooks Guide 10 of 45 Beginner
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 15 min
--syntax-check parses the YAML and the play structure without contacting any host. It will not catch a wrong module parameter or an undefined variable - those surface at run time - but it catches indentation, which is the mistake that actually happens.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
| ANS-B01 | 192.168.0.38 | Ubuntu 26.04 LTS | Managed Node (group: db) | 2 Core | 3 GB | 50 GB |
This guide includes
Use this when ad-hoc commands have stopped being enough. This matters because a playbook is a list of plays and a play is a list of tasks - and the output has a shape worth learning before you need to read it under pressure.
- writing a playbook as a list of plays
- checking it three ways before running anything at all
- running it, and learning the shape of the output
- running it again, and reading
changed=0as the entire point - seeing what a broken playbook looks like, from one missing colon
Before you start
- A control node configured as shown in the first step.
- The session creates
~/pb/site.yml, applies it to/opt/demoappon the managed node, and removes the directory at the end.
-
The configuration this guide assumes
-
A playbook is a list of plays
-
Check before you run
-
Run it
-
Run it again
-
What a broken playbook looks like