DevOps Bootcamp · Lesson

A Play = Hosts + Tasks

How a play maps tasks onto a host group.

Lesson 1 of 413 steps

A Play = Hosts + Tasks is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 1 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.

Meet the Play

A play is the heart of a playbook. It maps a set of tasks onto a group of hosts and runs them there. 🎯

Two Halves of a Play

Every play answers two questions: which machines, and what to do. That is exactly hosts plus tasks.

The hosts Key

The hosts key picks the target. It can be one host, a group from your inventory, or the special pattern all.

- name: Configure web servers
  hosts: web

The tasks List

Under tasks you list the actions to run, in order. Each task is one item that calls a module.

  tasks:
    - name: Install nginx
      ansible.builtin.package:
        name: nginx

A Play Is a List Item

A playbook is a YAML list of plays. The dash before name marks where each play begins.

- name: My first play
  hosts: all
  tasks: []

One Play, Many Hosts

The same task list runs on every host in the group. Ansible fans it out so ten servers get the identical configuration.

Each Task Calls a Module

A task is just a module call with arguments. The module does the real work, like installing a package or copying a file.

Putting It Together

Hosts on top, tasks below: that single block is a complete, runnable play. 🧩

- name: Web setup
  hosts: web
  tasks:
    - name: Ensure nginx is present
      ansible.builtin.package:
        name: nginx

Play-Level Settings

Keys beside hosts apply to the whole play. For example become tells every task in it to run with elevated privileges.

- hosts: web
  become: true
  tasks: []

Why This Mapping Matters

Separating hosts from tasks lets you reuse the same actions on different fleets just by changing the hosts line.

Plays Stack Up

One file can hold several plays. Ansible runs them top to bottom, so you can target web first, then db.

Quick Check

Let us make sure the core mapping is clear.

Recap

A play is hosts plus tasks: pick the machines, list the actions. Stack plays in one file to automate a whole fleet. ✅

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 “A Play = Hosts + Tasks” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “A Play = Hosts + Tasks”, 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 “A Play = Hosts + Tasks”?

How a play maps tasks onto a host group. 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 1 of 4.

How long does the “A Play = Hosts + Tasks” 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