Skip to content

Commit

Permalink
keep track of original inventory hostname in play context (#38818)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jctanner authored and bcoca committed Apr 16, 2018
1 parent 694d6b3 commit 068b9ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/ansible/executor/task_executor.py
Expand Up @@ -813,6 +813,9 @@ def _get_connection(self, variables, templar):

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()))

Expand All @@ -822,7 +825,9 @@ def _set_connection_options(self, variables, templar):
# 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
Expand Down

0 comments on commit 068b9ac

Please sign in to comment.