LOGBOOK

HELP

Quiz Entry - updated: 2026.10.30

Why would a playbook contain several plays, and how are they written?

To orchestrate a deployment where different host groups need different tasks in a fixed order, for example configure the web servers and then the database servers. Each play is simply another top-level list item with its own name, hosts and tasks.

# This is a simple playbook with two plays
- name: first play
  hosts: web.example.com
  tasks:
    - name: first task
      yum:
        name: httpd
        state: present
    - name: second task
      service:
        name: httpd
        enabled: true

- name: second play
  hosts: database.example.com
  tasks:
    - name: first task
      service:
        name: mariadb
        enabled: true

A play binds one set of hosts to an ordered list of tasks. When a job spans several kinds of machines, one play cannot express it, because a play has a single hosts target. So you write one play per target and put them in one playbook. Plays run in file order: Ansible finishes the first play on its hosts, then starts the second. That ordering is what makes the playbook an orchestration ("first the app servers, then the load balancer").

Watch the argument names: the yum module's option is state: present. A typo like status: present is rejected as an unsupported parameter.

Go deeper:

From Quiz: ITIA / Ansible Inventory, Configuration and Playbooks | Updated: Oct 30, 2026