From 8fdabfff50942c1fba95ef565317c27bb642aa15 Mon Sep 17 00:00:00 2001 From: Alicia Cozine Date: Mon, 12 Feb 2024 11:50:13 -0600 Subject: [PATCH] corrects docs on role deduplication --- docs/docsite/rst/playbook_guide/playbooks_reuse.rst | 2 ++ .../rst/playbook_guide/playbooks_reuse_roles.rst | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/docsite/rst/playbook_guide/playbooks_reuse.rst b/docs/docsite/rst/playbook_guide/playbooks_reuse.rst index 4e42fc8d28a..0afe67a04e5 100644 --- a/docs/docsite/rst/playbook_guide/playbooks_reuse.rst +++ b/docs/docsite/rst/playbook_guide/playbooks_reuse.rst @@ -69,6 +69,8 @@ Task include and import statements can be used at arbitrary depth. You can still use the bare :ref:`roles ` keyword at the play level to incorporate a role in a playbook statically. However, the bare :ref:`include ` keyword, once used for both task files and playbook-level includes, is now deprecated. +Ansible runs all roles reused with ``include_role`` and ``import_role``, even if the parameters on the roles are the same. See :ref:`run_role_twice` for more details. + Includes: dynamic reuse ----------------------- diff --git a/docs/docsite/rst/playbook_guide/playbooks_reuse_roles.rst b/docs/docsite/rst/playbook_guide/playbooks_reuse_roles.rst index 316d164c729..1815c157dd0 100644 --- a/docs/docsite/rst/playbook_guide/playbooks_reuse_roles.rst +++ b/docs/docsite/rst/playbook_guide/playbooks_reuse_roles.rst @@ -156,7 +156,7 @@ When using ``vars:`` within the ``roles:`` section of a playbook, the variables Including roles: dynamic reuse ------------------------------ -You can reuse roles dynamically anywhere in the ``tasks`` section of a play using ``include_role``. While roles added in a ``roles`` section run before any other tasks in a play, included roles run in the order they are defined. If there are other tasks before an ``include_role`` task, the other tasks will run first. +You can reuse roles dynamically anywhere in the ``tasks`` section of a play using ``include_role``. While roles added in a ``roles`` section run before any other tasks in a play, included roles run in the order they are defined. If there are other tasks before an ``include_role`` task, the other tasks will run first. Ansible does not deduplicate included roles, even if they have the exact same parameters, and setting ``allow_duplicates: false`` has no effect on ``include_role``. To include a role: @@ -246,6 +246,8 @@ You can pass other keywords, including variables and tags when importing roles: When you add a tag to an ``import_role`` statement, Ansible applies the tag to `all` tasks within the role. See :ref:`tag_inheritance` for details. +Ansible does not deduplicate imported roles, even if they have the exact same parameters, and setting ``allow_duplicates: false`` has no effect on ``import_role``. + .. _role_argument_spec: Role argument validation @@ -490,7 +492,7 @@ Ansible only executes each role once in a play, even if you define it multiple t - bar - foo -You have two options to force Ansible to run a role more than once. +You have three options to force Ansible to run a role more than once. Passing different parameters ---------------------------- @@ -521,6 +523,11 @@ This syntax also runs the ``foo`` role twice; In these examples, Ansible runs ``foo`` twice because each role definition has different parameters. +Using ``include_role`` or ``import_role`` +----------------------------------------- + +Ansible does not deduplicate imported or included roles. When you use ``include_role`` or ``import_role``, Ansible runs each role, as long as any conditions on those tasks are met. This is true even if the parameters are the same on multiple included or imported roles. + Using ``allow_duplicates: true`` --------------------------------