Make sure we're using the original host when processing include results

Also fixes a bug where we were passing an incorrect number of parameters to
_do_handler_run() when processing an include file in a handler task/block.

Fixes #13560
pull/13663/head
James Cammarata 9 years ago
parent 407d76b8d5
commit f41dd578b3

@ -49,9 +49,15 @@ class IncludedFile:
return "%s (%s): %s" % (self._filename, self._args, self._hosts) return "%s (%s): %s" % (self._filename, self._args, self._hosts)
@staticmethod @staticmethod
def process_include_results(results, tqm, iterator, loader, variable_manager): def process_include_results(results, tqm, iterator, inventory, loader, variable_manager):
included_files = [] included_files = []
def get_original_host(host):
if host.name in inventory._hosts_cache:
return inventory._hosts_cache[host.name]
else:
return inventory.get_host(host.name)
for res in results: for res in results:
if res._task.action == 'include': if res._task.action == 'include':
@ -67,9 +73,10 @@ class IncludedFile:
if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result: if 'skipped' in include_result and include_result['skipped'] or 'failed' in include_result:
continue continue
original_task = iterator.get_original_task(res._host, res._task) original_host = get_original_host(res._host)
original_task = iterator.get_original_task(original_host, res._task)
task_vars = variable_manager.get_vars(loader=loader, play=iterator._play, host=res._host, task=original_task) task_vars = variable_manager.get_vars(loader=loader, play=iterator._play, host=original_host, task=original_task)
templar = Templar(loader=loader, variables=task_vars) templar = Templar(loader=loader, variables=task_vars)
include_variables = include_result.get('include_variables', dict()) include_variables = include_result.get('include_variables', dict())
@ -116,6 +123,6 @@ class IncludedFile:
except ValueError: except ValueError:
included_files.append(inc_file) included_files.append(inc_file)
inc_file.add_host(res._host) inc_file.add_host(original_host)
return included_files return included_files

@ -576,6 +576,7 @@ class StrategyBase:
host_results, host_results,
self._tqm, self._tqm,
iterator=iterator, iterator=iterator,
inventory=self._inventory,
loader=self._loader, loader=self._loader,
variable_manager=self._variable_manager variable_manager=self._variable_manager
) )
@ -594,6 +595,7 @@ class StrategyBase:
for task in block.block: for task in block.block:
result = self._do_handler_run( result = self._do_handler_run(
handler=task, handler=task,
handler_name=None,
iterator=iterator, iterator=iterator,
play_context=play_context, play_context=play_context,
notified_hosts=included_file._hosts[:], notified_hosts=included_file._hosts[:],

@ -139,8 +139,14 @@ class StrategyModule(StrategyBase):
host_results.extend(results) host_results.extend(results)
try: try:
included_files = IncludedFile.process_include_results(host_results, self._tqm, iterator=iterator, included_files = IncludedFile.process_include_results(
loader=self._loader, variable_manager=self._variable_manager) host_results,
self._tqm,
iterator=iterator,
inventory=self._inventory,
loader=self._loader,
variable_manager=self._variable_manager
)
except AnsibleError as e: except AnsibleError as e:
return False return False

@ -261,8 +261,14 @@ class StrategyModule(StrategyBase):
break break
try: try:
included_files = IncludedFile.process_include_results(host_results, self._tqm, included_files = IncludedFile.process_include_results(
iterator=iterator, loader=self._loader, variable_manager=self._variable_manager) host_results,
self._tqm,
iterator=iterator,
inventory=self._inventory,
loader=self._loader,
variable_manager=self._variable_manager
)
except AnsibleError as e: except AnsibleError as e:
return False return False

Loading…
Cancel
Save