From 845935f74f55ffa70d6e452a1714a68c8a30ac63 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Fri, 24 Sep 2021 15:30:35 -0400 Subject: [PATCH] Revert "Compile role with parents in the task's dependency chain (#75165)" (#75779) This reverts commit 440cf15aeb134e7df3969d4481dbe027358d74db. --- changelogs/fragments/75165-fix-role-dep-chain.yaml | 4 ---- lib/ansible/playbook/role_include.py | 6 +++++- test/integration/targets/roles/39543.yml | 7 ------- test/integration/targets/roles/47023.yml | 5 ----- .../targets/roles/roles/39543_role1/tasks/main.yml | 5 ----- .../targets/roles/roles/39543_role2/tasks/main.yml | 2 -- .../targets/roles/roles/39543_role3/meta/main.yml | 2 -- .../targets/roles/roles/39543_role3/tasks/main.yml | 2 -- .../targets/roles/roles/47023_role1/defaults/main.yml | 1 - .../targets/roles/roles/47023_role1/tasks/main.yml | 1 - .../targets/roles/roles/47023_role1/vars/main.yml | 1 - .../targets/roles/roles/47023_role2/tasks/main.yml | 1 - .../targets/roles/roles/47023_role3/tasks/main.yml | 1 - .../targets/roles/roles/47023_role4/tasks/main.yml | 5 ----- test/integration/targets/roles/runme.sh | 11 ----------- 15 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 changelogs/fragments/75165-fix-role-dep-chain.yaml delete mode 100644 test/integration/targets/roles/39543.yml delete mode 100644 test/integration/targets/roles/47023.yml delete mode 100644 test/integration/targets/roles/roles/39543_role1/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/39543_role2/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/39543_role3/meta/main.yml delete mode 100644 test/integration/targets/roles/roles/39543_role3/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role1/defaults/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role1/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role1/vars/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role2/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role3/tasks/main.yml delete mode 100644 test/integration/targets/roles/roles/47023_role4/tasks/main.yml diff --git a/changelogs/fragments/75165-fix-role-dep-chain.yaml b/changelogs/fragments/75165-fix-role-dep-chain.yaml deleted file mode 100644 index c52c0111e0e..00000000000 --- a/changelogs/fragments/75165-fix-role-dep-chain.yaml +++ /dev/null @@ -1,4 +0,0 @@ -bugfixes: - - include_role - Only inherit from role parents in the current task dependency chain (https://github.com/ansible/ansible/issues/39543). - - include_role - Inherit from role parents beyond a depth of 3 (https://github.com/ansible/ansible/issues/47023). - - include_role - Inherit from role parents in the order of the task dependency chain. diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py index 9b493d9df96..c6227031ca7 100644 --- a/lib/ansible/playbook/role_include.py +++ b/lib/ansible/playbook/role_include.py @@ -100,7 +100,11 @@ class IncludeRole(TaskInclude): # compile role with parent roles as dependencies to ensure they inherit # variables - dep_chain = self.get_dep_chain() or [] + if not self._parent_role: + dep_chain = [] + else: + dep_chain = list(self._parent_role._parents) + dep_chain.append(self._parent_role) p_block = self.build_parent_block() diff --git a/test/integration/targets/roles/39543.yml b/test/integration/targets/roles/39543.yml deleted file mode 100644 index 94e9e6c9f4c..00000000000 --- a/test/integration/targets/roles/39543.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- hosts: all - gather_facts: no - roles: - - 39543_role1 - - role: 39543_role3 - when: false diff --git a/test/integration/targets/roles/47023.yml b/test/integration/targets/roles/47023.yml deleted file mode 100644 index 6b41b52f52e..00000000000 --- a/test/integration/targets/roles/47023.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- hosts: all - gather_facts: no - tasks: - - include_role: name=47023_role1 diff --git a/test/integration/targets/roles/roles/39543_role1/tasks/main.yml b/test/integration/targets/roles/roles/39543_role1/tasks/main.yml deleted file mode 100644 index 67c50ebedb7..00000000000 --- a/test/integration/targets/roles/roles/39543_role1/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -- debug: - msg: 'role1' - -- include_role: - name: 39543_role2 diff --git a/test/integration/targets/roles/roles/39543_role2/tasks/main.yml b/test/integration/targets/roles/roles/39543_role2/tasks/main.yml deleted file mode 100644 index 4870224356d..00000000000 --- a/test/integration/targets/roles/roles/39543_role2/tasks/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -- debug: - msg: 'role2' diff --git a/test/integration/targets/roles/roles/39543_role3/meta/main.yml b/test/integration/targets/roles/roles/39543_role3/meta/main.yml deleted file mode 100644 index 3980a3e5fc6..00000000000 --- a/test/integration/targets/roles/roles/39543_role3/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - 39543_role1 diff --git a/test/integration/targets/roles/roles/39543_role3/tasks/main.yml b/test/integration/targets/roles/roles/39543_role3/tasks/main.yml deleted file mode 100644 index 550f9972bc3..00000000000 --- a/test/integration/targets/roles/roles/39543_role3/tasks/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -- debug: - msg: 'role3' diff --git a/test/integration/targets/roles/roles/47023_role1/defaults/main.yml b/test/integration/targets/roles/roles/47023_role1/defaults/main.yml deleted file mode 100644 index 166caa33b30..00000000000 --- a/test/integration/targets/roles/roles/47023_role1/defaults/main.yml +++ /dev/null @@ -1 +0,0 @@ -my_default: defined diff --git a/test/integration/targets/roles/roles/47023_role1/tasks/main.yml b/test/integration/targets/roles/roles/47023_role1/tasks/main.yml deleted file mode 100644 index 9c408ba2edd..00000000000 --- a/test/integration/targets/roles/roles/47023_role1/tasks/main.yml +++ /dev/null @@ -1 +0,0 @@ -- include_role: name=47023_role2 diff --git a/test/integration/targets/roles/roles/47023_role1/vars/main.yml b/test/integration/targets/roles/roles/47023_role1/vars/main.yml deleted file mode 100644 index bfda56b9b80..00000000000 --- a/test/integration/targets/roles/roles/47023_role1/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ -my_var: defined diff --git a/test/integration/targets/roles/roles/47023_role2/tasks/main.yml b/test/integration/targets/roles/roles/47023_role2/tasks/main.yml deleted file mode 100644 index 4544215f84a..00000000000 --- a/test/integration/targets/roles/roles/47023_role2/tasks/main.yml +++ /dev/null @@ -1 +0,0 @@ -- include_role: name=47023_role3 diff --git a/test/integration/targets/roles/roles/47023_role3/tasks/main.yml b/test/integration/targets/roles/roles/47023_role3/tasks/main.yml deleted file mode 100644 index 9479fe3f3d8..00000000000 --- a/test/integration/targets/roles/roles/47023_role3/tasks/main.yml +++ /dev/null @@ -1 +0,0 @@ -- include_role: name=47023_role4 diff --git a/test/integration/targets/roles/roles/47023_role4/tasks/main.yml b/test/integration/targets/roles/roles/47023_role4/tasks/main.yml deleted file mode 100644 index 64c96e97dd6..00000000000 --- a/test/integration/targets/roles/roles/47023_role4/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -- debug: - msg: "Var is {{ my_var | default('undefined') }}" - -- debug: - msg: "Default is {{ my_default | default('undefined') }}" diff --git a/test/integration/targets/roles/runme.sh b/test/integration/targets/roles/runme.sh index edc13e0a6bb..5f11c1fca61 100755 --- a/test/integration/targets/roles/runme.sh +++ b/test/integration/targets/roles/runme.sh @@ -17,14 +17,3 @@ set -eux # ensure role data is merged correctly ansible-playbook data_integrity.yml -i ../../inventory "$@" - - -# ensure role vars are inherited correctly -ANSIBLE_PRIVATE_ROLE_VARS=True ansible-playbook 39543.yml -i ../../inventory "$@" | tee out.txt -test "$(grep '"msg": "role1"' -c out.txt)" = "1" -test "$(grep '"msg": "role2"' -c out.txt)" = "1" -test "$(grep '"msg": "role3"' -c out.txt)" = "0" - - -# test nested includes get parent roles greater than a depth of 3 -[ "$(ansible-playbook 47023.yml -i ../../inventory "$@" | grep '\<\(Default\|Var\)\>' | grep -c 'is defined')" = "2" ]