Quiz Entry - updated: 2026.10.30
A playbook contains two top-level items, - name: Webserver einrichten (keys hosts, vars, tasks; three tasks for yum, service and firewalld) and - name: Datenbankserver einrichten. How many plays and tasks are there, and how do you tell?
Two plays, because the outermost list has two dash items; the first play has three tasks, because its tasks list has three dash items. Plays and tasks are both objects; the playbook and tasks are lists.
Reading procedure, which works on any playbook:
- Find the outermost dashes. Each
-at column 0 (after the start marker) starts a play. Two dashes, two plays: "set up web server" and "set up database server" ("Webserver einrichten" and "Datenbankserver einrichten" in the German example). - Look at what follows a play's dash without dashes.
name,hosts,vars,tasksare key-value pairs at the same indentation, so the play is an object. - Open the
taskskey. Its value is a list; count the dashes one level in. In the first play: ensure Apache is installed (ansible.builtin.yum), start the Apache service (ansible.builtin.service), allow the Apache port in the firewall (ansible.builtin.firewalld). Three tasks. - Each task is an object again: a
nameplus a module key whose value is another object of arguments.
The vars: block (http_port: 80) is a named object inside the play; the firewall task uses it as port: "{{ http_port }}/tcp", so the port is defined once and reused.
Go deeper:
Ansible playbooks: playbook syntax (official docs) โ a two-play example (web servers, then databases) read the same way.