From 41bddb61b8f6c4340ca06969b344eea617fdb251 Mon Sep 17 00:00:00 2001 From: Kiyo Nagamine Date: Wed, 4 Dec 2019 00:21:54 +0900 Subject: [PATCH] Ensure `allow_duplicates: true` enables to run single role multiple times (#64902) (#65063) * Ensure `allow_duplicates: true` enables to run single role multiple times(#64902) * Changed return value in `_load_roles` . Fixes #64902 * Add changelog fragment * Add an integration test for the issue * Fix changelog generation error and integration test. * Fix yaml syntax error in changelog fragment * Fix typo in a changelog fragment of #64902 (cherry picked from commit daecbb9bf080bc639ca8a5e5d67cee5ed1a0b439) (cherry picked from commit 33094e6c8ef39f4ca292c30a32268ee889600d5e) --- .../64902-fix-allow-duplicates-in-single-role.yml | 4 ++++ lib/ansible/playbook/play.py | 8 +++----- .../include_import/roles/dup_allowed_role/meta/main.yml | 2 ++ .../include_import/roles/dup_allowed_role/tasks/main.yml | 3 +++ test/integration/targets/include_import/runme.sh | 4 ++++ .../include_import/tasks/test_allow_single_role_dup.yml | 8 ++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/64902-fix-allow-duplicates-in-single-role.yml create mode 100644 test/integration/targets/include_import/roles/dup_allowed_role/meta/main.yml create mode 100644 test/integration/targets/include_import/roles/dup_allowed_role/tasks/main.yml create mode 100644 test/integration/targets/include_import/tasks/test_allow_single_role_dup.yml 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..aba5152eb7f --- /dev/null +++ b/changelogs/fragments/64902-fix-allow-duplicates-in-single-role.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - "roles - Ensure that ``allow_duplicates: 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 e01b6141f8e..cd3966e0042 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -199,11 +199,9 @@ class Play(Base, Taggable, Become, 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