Skip to content

Commit 58659cf

Browse files
authored
Tagging nuance (#1900)
* Tagging nuance (cherry picked from commit 0cf6e62673cf7368e5223f52f335d4d9ab7bb1de) * izpell * ammended for handlers * remove flush example * add ref on handler limitations
1 parent 495d915 commit 58659cf

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

docs/docsite/rst/playbook_guide/playbooks_handlers.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,5 @@ Since Ansible 2.14 :ansplugin:`meta tasks <ansible.builtin.meta#module>` are all
211211
Limitations
212212
-----------
213213

214-
A handler cannot run ``import_role`` or ``include_role``.
214+
A handler cannot run ``import_role`` nor ``include_role``.
215+
Handlers :ref:`ignore tags <tags_on_handlers>`.

docs/docsite/rst/playbook_guide/playbooks_tags.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ If you have a large playbook, it may be useful to run only specific parts of it
99
#. Add tags to your tasks, either individually or with tag inheritance from a block, play, role, or import.
1010
#. Select or skip tags when you run your playbook.
1111

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+
1215
.. contents::
1316
:local:
1417

18+
1519
Adding tags with the tags keyword
1620
=================================
1721

@@ -81,6 +85,14 @@ You can apply the same tag to more than one individual task. This example tags s
8185
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.
8286

8387

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+
8496
.. _tags_on_blocks:
8597

8698
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
121133
tags: filesharing
122134
123135
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+
124153
.. _tags_on_plays:
125154

126155
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
156185
tasks:
157186
...
158187
188+
.. note::
189+
The tasks tagged will include all implicit tasks (like fact gathering) of the play, including those added via roles.
159190

160191
.. _tags_on_roles:
161192

@@ -192,6 +223,12 @@ or:
192223
# using YAML shorthand, this is equivalent to:
193224
# - { role: foo, tags: ["bar", "baz"] }
194225
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.
229+
See the tag inheritance section for details.
230+
231+
195232
.. _tags_on_includes:
196233

197234
Adding tags to includes

0 commit comments

Comments
 (0)