From 068b9ac523959cb101ef25bd26a1479f635d1b4a Mon Sep 17 00:00:00 2001 From: jctanner Date: Mon, 16 Apr 2018 17:16:57 -0400 Subject: [PATCH] keep track of original inventory hostname in play context (#38818) this change further enables the ansible-vcr project to collect fixtures per host in situations where the host context is totally lost due to delegation. * Keep some original pre-delegate values in connection options --- lib/ansible/executor/task_executor.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index d6e7bbdf54..ab6915dee6 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -813,6 +813,9 @@ class TaskExecutor: def _set_connection_options(self, variables, templar): + # Keep the pre-delegate values for these keys + PRESERVE_ORIG = ('inventory_hostname',) + # create copy with delegation built in final_vars = combine_vars(variables, variables.get('ansible_delegated_vars', dict()).get(self._task.delegate_to, dict())) @@ -822,7 +825,9 @@ class TaskExecutor: # create dict of 'templated vars' options = {'_extras': {}} for k in option_vars: - if k in final_vars: + if k in PRESERVE_ORIG: + options[k] = templar.template(variables[k]) + elif k in final_vars: options[k] = templar.template(final_vars[k]) # add extras if plugin supports them