You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docsite/rst/playbook_guide/playbooks_tags.rst
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,13 @@ If you have a large playbook, it may be useful to run only specific parts of it
9
9
#. Add tags to your tasks, either individually or with tag inheritance from a block, play, role, or import.
10
10
#. Select or skip tags when you run your playbook.
11
11
12
+
.. note::
13
+
The ``tags`` keyword is part of 'pre processing' the playbook and has high precedence when deciding what tasks are available to consider for execution.
14
+
12
15
.. contents::
13
16
:local:
14
17
18
+
15
19
Adding tags with the tags keyword
16
20
=================================
17
21
@@ -81,6 +85,14 @@ You can apply the same tag to more than one individual task. This example tags s
81
85
If you ran these four tasks in a playbook with ``--tags ntp``, Ansible would run the three tasks tagged ``ntp`` and skip the one task that does not have that tag.
82
86
83
87
88
+
.. _tags_on_handlers:
89
+
90
+
Adding tags to handlers
91
+
^^^^^^^^^^^^^^^^^^^^^^^
92
+
93
+
Handlers are a special case of tasks that only execute when notified, as such they ignore all tags and cannot be selected for nor against.
94
+
95
+
84
96
.. _tags_on_blocks:
85
97
86
98
Adding tags to blocks
@@ -121,6 +133,23 @@ If you want to apply a tag to many, but not all, of the tasks in your play, use
121
133
tags: filesharing
122
134
123
135
136
+
Be mindful that ``tag`` selection supersedes most other logic, including ``block`` error handling. Setting a tag on a task in a ``block`` but not in the ``rescue`` or ``always`` section will prevent those from triggering if your tags selection does not cover the tasks in those sections.
137
+
138
+
.. code-block:: yaml
139
+
140
+
- block:
141
+
- debug: msg=run with tag, but always fail
142
+
failed_when: true
143
+
tags: example
144
+
145
+
rescue:
146
+
- debug: msg=I always run because the block always fails, except if you select to only run 'example' tag
147
+
148
+
always:
149
+
- debug: msg=I always run, except if you select to only run 'example' tag
150
+
151
+
This example runs all 3 tasks if called without specifying ``--tags`` but only runs the first task if you run with ``--tags example``.
152
+
124
153
.. _tags_on_plays:
125
154
126
155
Adding tags to plays
@@ -156,6 +185,8 @@ If all the tasks in a play should get the same tag, you can add the tag at the l
156
185
tasks:
157
186
...
158
187
188
+
.. note::
189
+
The tasks tagged will include all implicit tasks (like fact gathering) of the play, including those added via roles.
159
190
160
191
.. _tags_on_roles:
161
192
@@ -192,6 +223,12 @@ or:
192
223
# using YAML shorthand, this is equivalent to:
193
224
# - { role: foo, tags: ["bar", "baz"] }
194
225
226
+
227
+
.. note::
228
+
When adding a tag at the role level, not only are all tasks tagged, but the role's dependencies also have their tasks tagged.
0 commit comments