mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
Stash post-validated fields of the task in the TaskResult
This allows us to have a snapshot of the fields, which we can restore on the pre-fork side so as to avoid having to re-template fields.
This commit is contained in:
parent
40235d7b99
commit
3d65482927
5 changed files with 54 additions and 26 deletions
|
@ -304,11 +304,6 @@ class StrategyBase:
|
|||
else:
|
||||
return False
|
||||
|
||||
# a Templar class to use for templating things later, as we're using
|
||||
# original/non-validated objects here on the manager side. We set the
|
||||
# variables in use later inside the loop below
|
||||
templar = Templar(loader=self._loader)
|
||||
|
||||
cur_pass = 0
|
||||
while True:
|
||||
try:
|
||||
|
@ -319,9 +314,13 @@ class StrategyBase:
|
|||
finally:
|
||||
self._results_lock.release()
|
||||
|
||||
# get the original host and task. We then assign them to the TaskResult for use in callbacks/etc.
|
||||
# get the original host and task. We then assign them to the TaskResult for use in callbacks/etc.
|
||||
original_host = get_original_host(task_result._host)
|
||||
original_task = iterator.get_original_task(original_host, task_result._task)
|
||||
found_task = iterator.get_original_task(original_host, task_result._task)
|
||||
original_task = found_task.copy(exclude_parent=True, exclude_tasks=True)
|
||||
original_task._parent = found_task._parent
|
||||
for (attr, val) in iteritems(task_result._task_fields):
|
||||
setattr(original_task, attr, val)
|
||||
|
||||
task_result._host = original_host
|
||||
task_result._task = original_task
|
||||
|
@ -348,12 +347,6 @@ class StrategyBase:
|
|||
self._tqm.send_callback('v2_runner_item_on_ok', task_result)
|
||||
continue
|
||||
|
||||
# get the vars for this task/host pair, make them the active set of vars for our templar above
|
||||
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=original_host, task=original_task)
|
||||
self.add_tqm_variables(task_vars, play=iterator._play)
|
||||
templar.set_available_variables(task_vars)
|
||||
|
||||
run_once = templar.template(original_task.run_once)
|
||||
if original_task.register:
|
||||
host_list = self.get_task_hosts(iterator, original_host, original_task)
|
||||
|
||||
|
@ -368,10 +361,10 @@ class StrategyBase:
|
|||
role_ran = False
|
||||
if task_result.is_failed():
|
||||
role_ran = True
|
||||
ignore_errors = templar.template(original_task.ignore_errors)
|
||||
ignore_errors = original_task.ignore_errors
|
||||
if not ignore_errors:
|
||||
display.debug("marking %s as failed" % original_host.name)
|
||||
if run_once:
|
||||
if original_task.run_once:
|
||||
# if we're using run_once, we have to fail every host here
|
||||
for h in self._inventory.get_hosts(iterator._play.hosts):
|
||||
if h.name not in self._tqm._unreachable_hosts:
|
||||
|
@ -488,7 +481,7 @@ class StrategyBase:
|
|||
item = result_item.get(loop_var, None)
|
||||
if item is not None:
|
||||
task_vars[loop_var] = item
|
||||
host_name = templar.template(original_task.delegate_to)
|
||||
host_name = original_task.delegate_to
|
||||
actual_host = self._inventory.get_host(host_name)
|
||||
if actual_host is None:
|
||||
actual_host = Host(name=host_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue