Table of Contents

Ansible - Tag

About

A tag permits to filter the execution of tasks

Built-in

special keywords:

By default, Ansible runs as if –tags all had been specified.

ansible-playbook playbook.yml -i hosts.ini --tags all

Example

tasks:
- debug:
    msg: "Always runs"
  tags:
    - always

- debug:
    msg: "runs when you use tag1"
  tags:
  - tag1

- debug:
    msg:"{{ showmevar }} - run only when a 'debug' tag is specified "
  tags: [ never, debug ]

Inheritancec

With the include_tasks, the tasks defined in my-tasks.yml will inherit the tag my-tag

tasks:
  ansible.builtin.include_tasks:
    file: my-tasks.yml
    apply:
      tags: my-tag

Documentation / Reference