Interview Prep/Ansible/Fundamentals and Architecture

Can a playbook have multiple plays? Why would you do that?

IntermediateConceptFundamentals and Architecture
Answer

Yes. A playbook is a list of plays, and each play maps a host pattern to tasks. Multiple plays let you orchestrate across tiers in one run: configure the database, then app servers, then the load balancer, each with its own hosts, become, variables and serial.

- hosts: db
  roles: [postgres]
- hosts: app
  roles: [app]
- hosts: lb
  roles: [haproxy]

Plays run sequentially. Data can pass between them through hostvars or set_fact on the hosts.

All Ansible questions Roadmap: Ansible

More on Fundamentals and Architecture