DevOps Bootcamp · Lesson

Multiple Plays in One Playbook

Target web then db in a single file.

Lesson 3 of 413 steps

Multiple Plays in One Playbook is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

More Than One Play

A playbook is a YAML list, so it can hold multiple plays. Each play targets its own host group. 🎭

Why Split Into Plays

Different tiers need different work. One play sets up web servers, another configures the database hosts.

Each Play Starts With a Dash

A new dash at the top level begins a new play. That is how Ansible knows one play ended and the next started.

- name: Web play
  hosts: web
  tasks: []

- name: DB play
  hosts: db
  tasks: []

Web Then DB

Plays run in file order. The web play finishes completely before the db play starts.

Independent hosts Lines

Each play has its own hosts value. They can point to totally separate groups with no overlap.

- hosts: web
  tasks: []
- hosts: db
  tasks: []

Separate Settings Per Play

Play-level keys like become or vars apply only to that play. The next play starts with its own clean settings.

Facts Per Play

By default each play gathers facts for its own hosts before tasks run, so the db play sees db machine data.

Orchestrating a Stack

Multiple plays let one file orchestrate a whole stack: configure the database, then the app, then the load balancer. 🏗️

A Three-Play File

Here three plays target three groups in sequence. One command rolls out the entire environment.

- hosts: db
  tasks: []
- hosts: app
  tasks: []
- hosts: lb
  tasks: []

One Command, Many Tiers

You still run it with a single ansible-playbook call. Ansible walks every play for you, top to bottom.

Keep Plays Focused

Give each play one clear job and one host group. Focused plays keep a large playbook easy to read and reuse.

Quick Check

Let us confirm how multiple plays execute.

Recap

One file can hold many plays, each with its own hosts and settings. They run in order to orchestrate a full stack. ✅

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Multiple Plays in One Playbook” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Multiple Plays in One Playbook”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Multiple Plays in One Playbook”?

Target web then db in a single file. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Multiple Plays in One Playbook” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. A Play = Hosts + Tasks
  2. Naming Tasks for Readable Output
  3. Multiple Plays in One Playbook
  4. Task Order & Top-Down Execution
← Back to DevOps Bootcamp