diff --git a/changelogs/fragments/64902-fix-allow-duplicates-in-single-role.yml b/changelogs/fragments/64902-fix-allow-duplicates-in-single-role.yml new file mode 100644 index 00000000000..045fe809761 --- /dev/null +++ b/changelogs/fragments/64902-fix-allow-duplicates-in-single-role.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - "roles - Ensure that ``allow_duplidates: true`` enables to run single + role multiple times (https://github.com/ansible/ansible/issues/64902)" diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 85f12132f24..eaf598d2ce4 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -201,11 +201,9 @@ class Play(Base, Taggable, CollectionSearch): for ri in role_includes: roles.append(Role.load(ri, play=self)) - return self._extend_value( - self.roles, - roles, - prepend=True - ) + self.roles[:0] = roles + + return self.roles def _load_vars_prompt(self, attr, ds): new_ds = preprocess_vars(ds) diff --git a/test/integration/targets/include_import/roles/dup_allowed_role/meta/main.yml b/test/integration/targets/include_import/roles/dup_allowed_role/meta/main.yml new file mode 100644 index 00000000000..61d3ffe4f94 --- /dev/null +++ b/test/integration/targets/include_import/roles/dup_allowed_role/meta/main.yml @@ -0,0 +1,2 @@ +--- +allow_duplicates: true diff --git a/test/integration/targets/include_import/roles/dup_allowed_role/tasks/main.yml b/test/integration/targets/include_import/roles/dup_allowed_role/tasks/main.yml new file mode 100644 index 00000000000..cad935e3c30 --- /dev/null +++ b/test/integration/targets/include_import/roles/dup_allowed_role/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- debug: + msg: "Tasks file inside role" diff --git a/test/integration/targets/include_import/runme.sh b/test/integration/targets/include_import/runme.sh index efa0a0ae01c..199cd472bc3 100755 --- a/test/integration/targets/include_import/runme.sh +++ b/test/integration/targets/include_import/runme.sh @@ -104,3 +104,7 @@ ansible-playbook test_loop_var_bleed.yaml "$@" # https://github.com/ansible/ansible/issues/56580 ansible-playbook valid_include_keywords/playbook.yml "$@" + +# https://github.com/ansible/ansible/issues/64902 +ansible-playbook tasks/test_allow_single_role_dup.yml 2>&1 | tee test_allow_single_role_dup.out +test "$(grep -c 'ok=3' test_allow_single_role_dup.out)" = 1 diff --git a/test/integration/targets/include_import/tasks/test_allow_single_role_dup.yml b/test/integration/targets/include_import/tasks/test_allow_single_role_dup.yml new file mode 100644 index 00000000000..3a6992fa4c8 --- /dev/null +++ b/test/integration/targets/include_import/tasks/test_allow_single_role_dup.yml @@ -0,0 +1,8 @@ +--- +- name: test for allow_duplicates with single role + hosts: localhost + gather_facts: false + roles: + - dup_allowed_role + - dup_allowed_role + - dup_allowed_role