|
|
|
@ -76,15 +76,16 @@ class StrategySentinel:
|
|
|
|
|
_sentinel = StrategySentinel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def post_process_whens(result, task, templar):
|
|
|
|
|
|
|
|
|
|
def post_process_whens(result, task, templar, task_vars):
|
|
|
|
|
cond = None
|
|
|
|
|
if task.changed_when:
|
|
|
|
|
with templar.set_temporary_context(available_variables=task_vars):
|
|
|
|
|
cond = Conditional(loader=templar._loader)
|
|
|
|
|
cond.when = task.changed_when
|
|
|
|
|
result['changed'] = cond.evaluate_conditional(templar, templar.available_variables)
|
|
|
|
|
|
|
|
|
|
if task.failed_when:
|
|
|
|
|
with templar.set_temporary_context(available_variables=task_vars):
|
|
|
|
|
if cond is None:
|
|
|
|
|
cond = Conditional(loader=templar._loader)
|
|
|
|
|
cond.when = task.failed_when
|
|
|
|
@ -92,6 +93,22 @@ def post_process_whens(result, task, templar):
|
|
|
|
|
result['failed_when_result'] = result['failed'] = failed_when_result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_item_vars(result, task):
|
|
|
|
|
item_vars = {}
|
|
|
|
|
if task.loop or task.loop_with:
|
|
|
|
|
loop_var = result.get('ansible_loop_var', 'item')
|
|
|
|
|
index_var = result.get('ansible_index_var')
|
|
|
|
|
if loop_var in result:
|
|
|
|
|
item_vars[loop_var] = result[loop_var]
|
|
|
|
|
if index_var and index_var in result:
|
|
|
|
|
item_vars[index_var] = result[index_var]
|
|
|
|
|
if '_ansible_item_label' in result:
|
|
|
|
|
item_vars['_ansible_item_label'] = result['_ansible_item_label']
|
|
|
|
|
if 'ansible_loop' in result:
|
|
|
|
|
item_vars['ansible_loop'] = result['ansible_loop']
|
|
|
|
|
return item_vars
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def results_thread_main(strategy):
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
@ -680,12 +697,32 @@ class StrategyBase:
|
|
|
|
|
# this task added a new host (add_host module)
|
|
|
|
|
new_host_info = result_item.get('add_host', dict())
|
|
|
|
|
self._add_host(new_host_info, result_item)
|
|
|
|
|
post_process_whens(result_item, original_task, handler_templar)
|
|
|
|
|
|
|
|
|
|
elif 'add_group' in result_item:
|
|
|
|
|
# this task added a new group (group_by module)
|
|
|
|
|
self._add_group(original_host, result_item)
|
|
|
|
|
post_process_whens(result_item, original_task, handler_templar)
|
|
|
|
|
|
|
|
|
|
if 'add_host' in result_item or 'add_group' in result_item:
|
|
|
|
|
item_vars = _get_item_vars(result_item, original_task)
|
|
|
|
|
found_task_vars = self._queued_task_cache.get((original_host.name, task_result._task._uuid))['task_vars']
|
|
|
|
|
if item_vars:
|
|
|
|
|
all_task_vars = combine_vars(found_task_vars, item_vars)
|
|
|
|
|
else:
|
|
|
|
|
all_task_vars = found_task_vars
|
|
|
|
|
all_task_vars[original_task.register] = wrap_var(result_item)
|
|
|
|
|
post_process_whens(result_item, original_task, handler_templar, all_task_vars)
|
|
|
|
|
if original_task.loop or original_task.loop_with:
|
|
|
|
|
new_item_result = TaskResult(
|
|
|
|
|
task_result._host,
|
|
|
|
|
task_result._task,
|
|
|
|
|
result_item,
|
|
|
|
|
task_result._task_fields,
|
|
|
|
|
)
|
|
|
|
|
self._tqm.send_callback('v2_runner_item_on_ok', new_item_result)
|
|
|
|
|
if result_item.get('changed', False):
|
|
|
|
|
task_result._result['changed'] = True
|
|
|
|
|
if result_item.get('failed', False):
|
|
|
|
|
task_result._result['failed'] = True
|
|
|
|
|
|
|
|
|
|
if 'ansible_facts' in result_item and original_task.action not in C._ACTION_DEBUG:
|
|
|
|
|
# if delegated fact and we are delegating facts, we need to change target host for them
|
|
|
|
|