Clarify how tag inheritance works (#28942)

Fixes #20119

Another crack at PR #27147
pull/28943/head
Sam Doran 7 years ago committed by scottb
parent 596dc8c442
commit cc7e38890c

@ -171,8 +171,13 @@ Dependencies
Roles can also be dependent on other roles, and when you install a role that has dependencies, those dependenices will automatically be installed. Roles can also be dependent on other roles, and when you install a role that has dependencies, those dependenices will automatically be installed.
You specify role dependencies in the *meta/main.yml* file by providing a list of roles. If the source of a role is Galaxy, you can simply specify the role in You specify role dependencies in the ``meta/main.yml`` file by providing a list of roles. If the source of a role is Galaxy, you can simply specify the role in
the format *username.role_name*. The more complex format used in *requirements.yml* is also supported, allowing you to provide src, scm, version and name. the format ``username.role_name``. The more complex format used in ``requirements.yml`` is also supported, allowing you to provide ``src``, ``scm``, ``version``, and ``name``.
Tags are inherited *down* the dependency chain. In order for tags to be applied to a role and all its dependencies, the tag should be applied to the role, not to all the tasks within a role.
Roles listed as dependencies are subject to conditionals and tag filtering, and may not execute fully depeneding on
what tags and conditinoals are applied.
Dependencies found in Galaxy can be specified as follows: Dependencies found in Galaxy can be specified as follows:
@ -193,13 +198,12 @@ The complex form can also be used as follows:
version: 775396299f2da1f519f0d8885022ca2d6ee80ee8 version: 775396299f2da1f519f0d8885022ca2d6ee80ee8
name: composer name: composer
When dependencies are encountered by ``ansible-galaxy``, it will automatically install each dependency to the *roles_path*. To understand how dependencies When dependencies are encountered by ``ansible-galaxy``, it will automatically install each dependency to the ``roles_path``. To understand how dependencies are handled during play execution, see :doc:`playbooks_reuse_roles`.
are handled during play execution, see :doc:`playbooks_reuse_roles`.
.. note:: .. note::
At the time of this writing, the Galaxy website expects all role dependencies to exist in Galaxy, and therefore dependencies to be specified in the At the time of this writing, the Galaxy website expects all role dependencies to exist in Galaxy, and therefore dependencies to be specified in the
*username.role_name* format. If you import a role with a dependency where the *src* value is a URL, the import process will fail. ``username.role_name`` format. If you import a role with a dependency where the ``src`` value is a URL, the import process will fail.
Create roles Create roles
------------ ------------

@ -83,7 +83,7 @@ When used in this manner, the order of execution for your playbook is as follows
- Any ``pre_tasks`` defined in the play. - Any ``pre_tasks`` defined in the play.
- Any handlers triggered so far will be run. - Any handlers triggered so far will be run.
- Each role listed in ``roles`` will execute in turn. Any role dependencies defined in the roles ``meta/main.yml`` will be run first. - Each role listed in ``roles`` will execute in turn. Any role dependencies defined in the roles ``meta/main.yml`` will be run first, subject to tag filtering and conditionals.
- Any ``tasks`` defined in the play. - Any ``tasks`` defined in the play.
- Any handlers triggered so far will be run. - Any handlers triggered so far will be run.
- Any ``post_tasks`` defined in the play. - Any ``post_tasks`` defined in the play.
@ -93,7 +93,7 @@ When used in this manner, the order of execution for your playbook is as follows
See below for more information regarding role dependencies. See below for more information regarding role dependencies.
.. note:: .. note::
If using tags with tasks (described later as a means of only running part of a playbook), be sure to also tag your pre_tasks and post_tasks and pass those along as well, especially if the pre and post tasks are used for monitoring outage window control or load balancing. If using tags with tasks (described later as a means of only running part of a playbook), be sure to also tag your pre_tasks, post_tasks, and role dependencies and pass those along as well, especially if the pre/post tasks and role dependencies are used for monitoring outage window control or load balancing.
As of Ansible 2.4, you can now use roles inline with any other tasks using ``import_role`` or ``include_role``:: As of Ansible 2.4, you can now use roles inline with any other tasks using ``import_role`` or ``include_role``::

@ -62,8 +62,7 @@ Example::
Tag Inheritance Tag Inheritance
``````````````` ```````````````
You can apply tags to more than tasks, but they ONLY affect the tasks themselves. Applying tags anywhere else is just a You can apply tags to more than tasks, but they ONLY affect the tasks themselves. Applying tags anywhere else is just a convenience so you don't have to write it on every task::
convenience so you don't have to write it on every task::
- hosts: all - hosts: all
tags: tags:
@ -90,6 +89,11 @@ All of these apply the specified tags to EACH task inside the play, included
file, or role, so that these tasks can be selectively run when the playbook file, or role, so that these tasks can be selectively run when the playbook
is invoked with the corresponding tags. is invoked with the corresponding tags.
Tags are inherited *down* the dependency chain. In order for tags to be applied to a role and all its dependencies,
the tag should be applied to the role, not to all the tasks within a role.
You can see which tags are applied to tasks by running ``ansible-playbook`` with the ``--list-tasks`` option. You can display all tags using the ``--list-tags`` option.
.. _special_tags: .. _special_tags:
Special Tags Special Tags

Loading…
Cancel
Save