Skip to content

Commit

Permalink
use term variable when passing variables to roles
Browse files Browse the repository at this point in the history
Use terms clearly. Role parameters exist as well (see ansible#50278), but the example uses variables.
So use the term variable.
  • Loading branch information
SimonHeimberg committed Dec 2, 2020
1 parent e671fc2 commit 3aec155
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/docsite/rst/user_guide/playbooks_reuse_roles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Variables of the role (from section `vars:` and from `roles/x/vars/main.yml`) ar
Running a role multiple times in one playbook
=============================================

Ansible only executes each role once, even if you define it multiple times, unless the parameters defined on the role are different for each definition. For example, Ansible only runs the role ``foo`` once in a play like this:
Ansible only executes each role once, even if you define it multiple times, unless the variabless defined on the role are different for each definition. For example, Ansible only runs the role ``foo`` once in a play like this:

.. code-block:: yaml
Expand All @@ -278,10 +278,10 @@ Ansible only executes each role once, even if you define it multiple times, unle
You have two options to force Ansible to run a role more than once.

Passing different parameters
Passing different variables
----------------------------

You can pass different parameters in each role definition as:
You can pass different variables in each role definition as:

.. code-block:: yaml
Expand All @@ -305,7 +305,7 @@ or
vars:
message: "second"
In this example, because each role definition has different parameters, Ansible runs ``foo`` twice.
In this example, because each role definition has different variables, Ansible runs ``foo`` twice.

Using ``allow_duplicates: true``
--------------------------------
Expand Down Expand Up @@ -334,7 +334,7 @@ Using role dependencies

Role dependencies let you automatically pull in other roles when using a role. Ansible does not execute role dependencies when you include or import a role. You must use the ``roles`` keyword if you want Ansible to execute role dependencies.

Role dependencies are stored in the ``meta/main.yml`` file within the role directory. This file should contain a list of roles and parameters to insert before the specified role. For example:
Role dependencies are stored in the ``meta/main.yml`` file within the role directory. This file should contain a list of roles and variables to insert before the specified role. For example:

.. code-block:: yaml
Expand All @@ -343,21 +343,21 @@ Role dependencies are stored in the ``meta/main.yml`` file within the role direc
dependencies:
- role: common
vars:
some_parameter: 3
some_parameter_var: 3
- role: apache
vars:
apache_port: 80
- role: postgres
vars:
dbname: blarg
other_parameter: 12
other_parameter_var: 12
Ansible always executes role dependencies before the role that includes them. Ansible executes recursive role dependencies as well. If one role depends on a second role, and the second role depends on a third role, Ansible executes the third role, then the second role, then the first role.

Running role dependencies multiple times in one playbook
--------------------------------------------------------

Ansible treats duplicate role dependencies like duplicate roles listed under ``roles:``: Ansible only executes role dependencies once, even if defined multiple times, unless the parameters, tags, or when clause defined on the role are different for each definition. If two roles in a playbook both list a third role as a dependency, Ansible only runs that role dependency once, unless you pass different parameters, tags, when clause, or use ``allow_duplicates: true`` in the dependent (third) role. See :ref:`Galaxy role dependencies <galaxy_dependencies>` for more details.
Ansible treats duplicate role dependencies like duplicate roles listed under ``roles:``: Ansible only executes role dependencies once, even if defined multiple times, unless the variables, tags, or when clause defined on the role are different for each definition. If two roles in a playbook both list a third role as a dependency, Ansible only runs that role dependency once, unless you pass different variables, tags, when clause, or use ``allow_duplicates: true`` in the dependent (third) role. See :ref:`Galaxy role dependencies <galaxy_dependencies>` for more details.

For example, a role named ``car`` depends on a role named ``wheel`` as follows:

Expand Down Expand Up @@ -407,7 +407,7 @@ The resulting order of execution would be as follows:
...
car
To use ``allow_duplicates: true`` with role dependencies, you must specify it for the dependent role, not for the parent role. In the example above, ``allow_duplicates: true`` appears in the ``meta/main.yml`` of the ``tire`` and ``brake`` roles. The ``wheel`` role does not require ``allow_duplicates: true``, because each instance defined by ``car`` uses different parameter values.
To use ``allow_duplicates: true`` with role dependencies, you must specify it for the dependent role, not for the parent role. In the example above, ``allow_duplicates: true`` appears in the ``meta/main.yml`` of the ``tire`` and ``brake`` roles. The ``wheel`` role does not require ``allow_duplicates: true``, because each instance defined by ``car`` uses different variable values.

.. note::
See :ref:`playbooks_variables` for details on how Ansible chooses among variable values defined in different places (variable inheritance and scope).
Expand Down

0 comments on commit 3aec155

Please sign in to comment.