From 2a4e92aab793684324af77bb110d5ed1af84e2fb Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 30 Aug 2018 17:11:32 -0500 Subject: [PATCH] ensure if we get a non-Task object in _get_delegated_vars, we return early (#44934) --- changelogs/fragments/delegate-to-get-vars-no-task.yaml | 2 ++ lib/ansible/vars/manager.py | 4 ++++ .../targets/include_import/apply/include_apply.yml | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/delegate-to-get-vars-no-task.yaml diff --git a/changelogs/fragments/delegate-to-get-vars-no-task.yaml b/changelogs/fragments/delegate-to-get-vars-no-task.yaml new file mode 100644 index 0000000000..7a2035f587 --- /dev/null +++ b/changelogs/fragments/delegate-to-get-vars-no-task.yaml @@ -0,0 +1,2 @@ +bugfixes: +- delegate_to - ensure if we get a non-Task object in _get_delegated_vars, we return early (https://github.com/ansible/ansible/pull/44934) diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index ebbfa6aedc..921e63d92a 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -487,6 +487,10 @@ class VariableManager: return variables def _get_delegated_vars(self, play, task, existing_variables): + if not hasattr(task, 'loop'): + # This "task" is not a Task, so we need to skip it + return {} + # we unfortunately need to template the delegate_to field here, # as we're fetching vars before post_validate has been called on # the task that has been passed in diff --git a/test/integration/targets/include_import/apply/include_apply.yml b/test/integration/targets/include_import/apply/include_apply.yml index ca41b38df5..32c6e5e9f0 100644 --- a/test/integration/targets/include_import/apply/include_apply.yml +++ b/test/integration/targets/include_import/apply/include_apply.yml @@ -43,3 +43,8 @@ - include_role2_result is undefined tags: - always + + - include_role: + name: include_role + apply: + delegate_to: testhost2