DevOps Bootcamp · Lesson

Tagging Tasks, Plays & Roles

Attach labels to runnable units.

Lesson 1 of 413 steps

Tagging Tasks, Plays & Roles 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.

Why Label Your Work

A big playbook does many things. Tags are simple labels you stick on tasks so you can later run just the parts you want. 🏷️

Tagging a Single Task

Add a tags key to any task with a list of label names. Here the task carries the install tag.

- name: Install nginx
  ansible.builtin.package:
    name: nginx
    state: present
  tags:
    - install

One Task, Many Tags

A task can wear several tags at once. Running any one of them will include this task in the run.

tags:
  - install
  - packages
  - web

Short YAML Form

For a single tag you can skip the list and write it inline. Both forms mean exactly the same thing.

tags: install

Tagging a Whole Play

Put tags at the play level and every task inside inherits them. Great for grouping a play by its purpose.

- hosts: web
  tags:
    - web
  tasks:
    - ansible.builtin.debug:
        msg: hi

Tags Are Inherited

A tag set on a play or block flows down to all its tasks. The child tasks keep any tags of their own as well.

Tagging a Block

Wrap related tasks in a block and tag the block once. Every task within shares that label, keeping things tidy.

- block:
    - ansible.builtin.service:
        name: nginx
        state: started
  tags:
    - service

Tagging a Role

When you include a role, attach tags there. Every task the role contributes picks up those tags automatically.

roles:
  - role: nginx
    tags:
      - web

Good Tag Names

Pick clear, reusable names like install, config or deploy. Consistent tags across plays let you slice work the same way everywhere.

Tags Are Just Metadata

Tags change nothing on their own. They simply mark tasks so the command line can later pick which marked tasks to run.

A Fully Tagged Task

Here a task is named, does real work, and is labeled with two tags ready for selective runs. 🎯

- name: Deploy config
  ansible.builtin.template:
    src: app.conf.j2
    dest: /etc/app.conf
  tags:
    - config
    - deploy

Quick Check

You add tags to a play. What happens to its tasks?

Recap

You learned to attach tags to tasks, blocks, plays and roles, and that tags on a parent flow down to every task inside. ✅

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 “Tagging Tasks, Plays & Roles” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Tagging Tasks, Plays & Roles”, 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 “Tagging Tasks, Plays & Roles”?

Attach labels to runnable units. 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 “Tagging Tasks, Plays & Roles” 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. Tagging Tasks, Plays & Roles
  2. Filter Runs with --tags & --skip-tags
  3. The always & never Special Tags
  4. List Tags & Tasks Before Running
← Back to DevOps Bootcamp