0Pricing
Ansible Academy · Lesson

Tagging Tasks, Plays & Roles

Attach labels to runnable units.

Tagging Tasks, Plays & Roles is a free Ansible Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. ✅

Frequently asked questions

Is the “Tagging Tasks, Plays & Roles” lesson free?

Yes — the full text of “Tagging Tasks, Plays & Roles” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “Tagging Tasks, Plays & Roles”?

Attach labels to runnable units. You practise Ansible Academy 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 Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

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 Ansible Academy lesson?

Yes. Every Ansible Academy 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 Ansible Academy