From d5e4f37ca0b814e76d53cbceedd7d6adf4f96437 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 23 Oct 2018 11:08:48 -0500 Subject: [PATCH] Ensure we don't overwrite roles from include/import_role when loading the play (#47512) * Ensure we don't overwrite roles from include/import_role when loading the play. Fixes #47454 * Add changelog fragment --- changelogs/fragments/no-overwrite-roles.yaml | 2 ++ lib/ansible/playbook/play.py | 7 ++++++- .../include_import/public_exposure/no_overwrite_roles.yml | 4 ++++ .../public_exposure/roles/call_import/tasks/main.yml | 6 ++++++ test/integration/targets/include_import/runme.sh | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/no-overwrite-roles.yaml create mode 100644 test/integration/targets/include_import/public_exposure/no_overwrite_roles.yml create mode 100644 test/integration/targets/include_import/public_exposure/roles/call_import/tasks/main.yml diff --git a/changelogs/fragments/no-overwrite-roles.yaml b/changelogs/fragments/no-overwrite-roles.yaml new file mode 100644 index 00000000000..efd7061584c --- /dev/null +++ b/changelogs/fragments/no-overwrite-roles.yaml @@ -0,0 +1,2 @@ +bugfixes: +- roles - Ensure that we don't overwrite roles that have been registered (from imports) while parsing roles under the roles header (https://github.com/ansible/ansible/issues/47454) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 370a77f4df6..2469122ca1f 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -195,7 +195,12 @@ class Play(Base, Taggable, Become): roles = [] for ri in role_includes: roles.append(Role.load(ri, play=self)) - return roles + + return self._extend_value( + self.roles, + roles, + prepend=True + ) def _load_vars_prompt(self, attr, ds): new_ds = preprocess_vars(ds) diff --git a/test/integration/targets/include_import/public_exposure/no_overwrite_roles.yml b/test/integration/targets/include_import/public_exposure/no_overwrite_roles.yml new file mode 100644 index 00000000000..6a1d9bffcd9 --- /dev/null +++ b/test/integration/targets/include_import/public_exposure/no_overwrite_roles.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: false + roles: + - call_import diff --git a/test/integration/targets/include_import/public_exposure/roles/call_import/tasks/main.yml b/test/integration/targets/include_import/public_exposure/roles/call_import/tasks/main.yml new file mode 100644 index 00000000000..d6b28f09ddc --- /dev/null +++ b/test/integration/targets/include_import/public_exposure/roles/call_import/tasks/main.yml @@ -0,0 +1,6 @@ +- import_role: + name: regular + +- assert: + that: + - regular_defaults_var is defined diff --git a/test/integration/targets/include_import/runme.sh b/test/integration/targets/include_import/runme.sh index 066c88ca28f..308a8af8094 100755 --- a/test/integration/targets/include_import/runme.sh +++ b/test/integration/targets/include_import/runme.sh @@ -82,3 +82,4 @@ test "$(grep -c '"item=foo"' test_include_dupe_loop.out)" = 3 ansible-playbook public_exposure/playbook.yml -i ../../inventory "$@" ansible-playbook public_exposure/no_bleeding.yml -i ../../inventory "$@" +ansible-playbook public_exposure/no_overwrite_roles.yml -i ../../inventory "$@"