mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00: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:
@@ -115,7 +115,12 @@ class WorkerProcess(multiprocessing.Process):
|
||||
display.debug("done running TaskExecutor() for %s/%s" % (self._host, self._task))
|
||||
self._host.vars = dict()
|
||||
self._host.groups = []
|
||||
task_result = TaskResult(self._host.name, self._task._uuid, executor_result)
|
||||
task_result = TaskResult(
|
||||
self._host.name,
|
||||
self._task._uuid,
|
||||
executor_result,
|
||||
task_fields=self._task.dump_attrs(),
|
||||
)
|
||||
|
||||
# put the result on the result queue
|
||||
display.debug("sending task result")
|
||||
@@ -125,7 +130,12 @@ class WorkerProcess(multiprocessing.Process):
|
||||
except AnsibleConnectionFailure:
|
||||
self._host.vars = dict()
|
||||
self._host.groups = []
|
||||
task_result = TaskResult(self._host.name, self._task._uuid, dict(unreachable=True))
|
||||
task_result = TaskResult(
|
||||
self._host.name,
|
||||
self._task._uuid,
|
||||
dict(unreachable=True),
|
||||
task_fields=self._task.dump_attrs(),
|
||||
)
|
||||
self._rslt_q.put(task_result, block=False)
|
||||
|
||||
except Exception as e:
|
||||
@@ -133,7 +143,12 @@ class WorkerProcess(multiprocessing.Process):
|
||||
try:
|
||||
self._host.vars = dict()
|
||||
self._host.groups = []
|
||||
task_result = TaskResult(self._host.name, self._task._uuid, dict(failed=True, exception=to_text(traceback.format_exc()), stdout=''))
|
||||
task_result = TaskResult(
|
||||
self._host.name,
|
||||
self._task._uuid,
|
||||
dict(failed=True, exception=to_text(traceback.format_exc()), stdout=''),
|
||||
task_fields=self._task.dump_attrs(),
|
||||
)
|
||||
self._rslt_q.put(task_result, block=False)
|
||||
except:
|
||||
display.debug(u"WORKER EXCEPTION: %s" % to_text(e))
|
||||
|
||||
@@ -291,7 +291,15 @@ class TaskExecutor:
|
||||
templar = Templar(loader=self._loader, shared_loader_obj=self._shared_loader_obj, variables=self._job_vars)
|
||||
res['_ansible_item_label'] = templar.template(label)
|
||||
|
||||
self._rslt_q.put(TaskResult(self._host.name, self._task._uuid, res), block=False)
|
||||
self._rslt_q.put(
|
||||
TaskResult(
|
||||
self._host.name,
|
||||
self._task._uuid,
|
||||
res,
|
||||
task_fields=self._task.dump_attrs(),
|
||||
),
|
||||
block=False,
|
||||
)
|
||||
results.append(res)
|
||||
del task_vars[loop_var]
|
||||
|
||||
@@ -565,7 +573,7 @@ class TaskExecutor:
|
||||
result['_ansible_retry'] = True
|
||||
result['retries'] = retries
|
||||
display.debug('Retrying task, attempt %d of %d' % (attempt, retries))
|
||||
self._rslt_q.put(TaskResult(self._host.name, self._task._uuid, result), block=False)
|
||||
self._rslt_q.put(TaskResult(self._host.name, self._task._uuid, result, task_fields=self._task.dump_attrs()), block=False)
|
||||
time.sleep(delay)
|
||||
else:
|
||||
if retries > 1:
|
||||
|
||||
@@ -28,14 +28,20 @@ class TaskResult:
|
||||
the result of a given task.
|
||||
'''
|
||||
|
||||
def __init__(self, host, task, return_data):
|
||||
def __init__(self, host, task, return_data, task_fields=None):
|
||||
self._host = host
|
||||
self._task = task
|
||||
|
||||
if isinstance(return_data, dict):
|
||||
self._result = return_data.copy()
|
||||
else:
|
||||
self._result = DataLoader().load(return_data)
|
||||
|
||||
if task_fields is None:
|
||||
self._task_fields = dict()
|
||||
else:
|
||||
self._task_fields = task_fields
|
||||
|
||||
def is_changed(self):
|
||||
return self._check_key('changed')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user