Add skip_reason to meta task skips (#71355)
Change: - Make them more consistent with other tasks. Test Plan: - CI, new test Tickets: - Refs #71009 Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
parent
a479b003e8
commit
e5bb7b1a16
3 changed files with 14 additions and 1 deletions
2
changelogs/fragments/71355_execute_meta_skip_reason.yml
Normal file
2
changelogs/fragments/71355_execute_meta_skip_reason.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- meta - now include a ``skip_reason`` when skipped (https://github.com/ansible/ansible/pull/71355).
|
|
@ -1138,6 +1138,7 @@ class StrategyBase:
|
||||||
|
|
||||||
skipped = False
|
skipped = False
|
||||||
msg = ''
|
msg = ''
|
||||||
|
skip_reason = '%s conditional evaluated to False' % meta_action
|
||||||
self._tqm.send_callback('v2_playbook_on_task_start', task, is_conditional=False)
|
self._tqm.send_callback('v2_playbook_on_task_start', task, is_conditional=False)
|
||||||
|
|
||||||
# These don't support "when" conditionals
|
# These don't support "when" conditionals
|
||||||
|
@ -1163,6 +1164,7 @@ class StrategyBase:
|
||||||
msg = "facts cleared"
|
msg = "facts cleared"
|
||||||
else:
|
else:
|
||||||
skipped = True
|
skipped = True
|
||||||
|
skip_reason += ', not clearing facts and fact cache for %s' % target_host.name
|
||||||
elif meta_action == 'clear_host_errors':
|
elif meta_action == 'clear_host_errors':
|
||||||
if _evaluate_conditional(target_host):
|
if _evaluate_conditional(target_host):
|
||||||
for host in self._inventory.get_hosts(iterator._play.hosts):
|
for host in self._inventory.get_hosts(iterator._play.hosts):
|
||||||
|
@ -1172,6 +1174,7 @@ class StrategyBase:
|
||||||
msg = "cleared host errors"
|
msg = "cleared host errors"
|
||||||
else:
|
else:
|
||||||
skipped = True
|
skipped = True
|
||||||
|
skip_reason += ', not clearing host error state for %s' % target_host.name
|
||||||
elif meta_action == 'end_play':
|
elif meta_action == 'end_play':
|
||||||
if _evaluate_conditional(target_host):
|
if _evaluate_conditional(target_host):
|
||||||
for host in self._inventory.get_hosts(iterator._play.hosts):
|
for host in self._inventory.get_hosts(iterator._play.hosts):
|
||||||
|
@ -1180,6 +1183,7 @@ class StrategyBase:
|
||||||
msg = "ending play"
|
msg = "ending play"
|
||||||
else:
|
else:
|
||||||
skipped = True
|
skipped = True
|
||||||
|
skip_reason += ', continuing play'
|
||||||
elif meta_action == 'end_host':
|
elif meta_action == 'end_host':
|
||||||
if _evaluate_conditional(target_host):
|
if _evaluate_conditional(target_host):
|
||||||
iterator._host_states[target_host.name].run_state = iterator.ITERATING_COMPLETE
|
iterator._host_states[target_host.name].run_state = iterator.ITERATING_COMPLETE
|
||||||
|
@ -1187,6 +1191,8 @@ class StrategyBase:
|
||||||
msg = "ending play for %s" % target_host.name
|
msg = "ending play for %s" % target_host.name
|
||||||
else:
|
else:
|
||||||
skipped = True
|
skipped = True
|
||||||
|
skip_reason += ", continuing execution for %s" % target_host.name
|
||||||
|
# TODO: Nix msg here? Left for historical reasons, but skip_reason exists now.
|
||||||
msg = "end_host conditional evaluated to false, continuing execution for %s" % target_host.name
|
msg = "end_host conditional evaluated to false, continuing execution for %s" % target_host.name
|
||||||
elif meta_action == 'reset_connection':
|
elif meta_action == 'reset_connection':
|
||||||
all_vars = self._variable_manager.get_vars(play=iterator._play, host=target_host, task=task,
|
all_vars = self._variable_manager.get_vars(play=iterator._play, host=target_host, task=task,
|
||||||
|
@ -1233,12 +1239,16 @@ class StrategyBase:
|
||||||
result = {'msg': msg}
|
result = {'msg': msg}
|
||||||
if skipped:
|
if skipped:
|
||||||
result['skipped'] = True
|
result['skipped'] = True
|
||||||
|
result['skip_reason'] = skip_reason
|
||||||
else:
|
else:
|
||||||
result['changed'] = False
|
result['changed'] = False
|
||||||
|
|
||||||
display.vv("META: %s" % msg)
|
display.vv("META: %s" % msg)
|
||||||
|
|
||||||
return [TaskResult(target_host, task, result)]
|
res = TaskResult(target_host, task, result)
|
||||||
|
if skipped:
|
||||||
|
self._tqm.send_callback('v2_runner_on_skipped', res)
|
||||||
|
return [res]
|
||||||
|
|
||||||
def get_hosts_left(self, iterator):
|
def get_hosts_left(self, iterator):
|
||||||
''' returns list of available hosts for this iterator by filtering out unreachables '''
|
''' returns list of available hosts for this iterator by filtering out unreachables '''
|
||||||
|
|
|
@ -8,6 +8,7 @@ for test_strategy in linear free; do
|
||||||
|
|
||||||
grep -q "META: end_host conditional evaluated to false, continuing execution for testhost" <<< "$out"
|
grep -q "META: end_host conditional evaluated to false, continuing execution for testhost" <<< "$out"
|
||||||
grep -q "META: ending play for testhost2" <<< "$out"
|
grep -q "META: ending play for testhost2" <<< "$out"
|
||||||
|
grep -q '"skip_reason": "end_host conditional evaluated to False, continuing execution for testhost"' <<< "$out"
|
||||||
grep -q "play not ended for testhost" <<< "$out"
|
grep -q "play not ended for testhost" <<< "$out"
|
||||||
grep -qv "play not ended for testhost2" <<< "$out"
|
grep -qv "play not ended for testhost2" <<< "$out"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue