Tags¶
When you apply tags to things, you can then control whether they’re executed by adding command line options.
How to tag things¶
Plays and tasks have optional tags
attributes where you can
specify a list of tags. Here are some tagged Task s:
tasks:
- module: parm1=a parm2=b
tags:
- packages
- module2: parm1=x parm2=y
tags:
- configuration
And here’s a playbook with some tagged Play s:
- hosts: all
tags:
- foo
- bar
roles:
- role1
- role2
You can also apply tags when invoking a role from a playbook:
roles:
- { role: webserver, port: 5000, tags: [ 'web', 'foo' ] }
and when including tasks:
- include: foo.yml
tags: [web,foo]
What tags do¶
Adding a tag to a play or task says that if ansible is invoked
with --tags=x,y,z
, that the tagged play or task will only
be executed if at least one of its tags is included in the list
of tags from the command line.
Specifying --tags=all
is equivalent to the default behavior,
where all playbooks and tasks are run regardless of their tags.
Specifying --tags=tagged
runs only things that have some
tag, while --tags=untagged
runs only things that have no
tag.
You could alternatively invoke ansible with --skip-tags=a,b,c
and it will execute all plays and tasks that are not tagged
with a, b, or c.
Presumably --skip-tags=tagged
does the opposite of --tags=tagged
,
and --skip-tags=untagged
does the opposite of --tags=untagged
.
If a play or task is tagged always
, then it will be executed
unless ansible is invoked with skip-tags=always
.