summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/fragments/71355_execute_meta_skip_reason.yml2
-rw-r--r--lib/ansible/plugins/strategy/__init__.py12
-rwxr-xr-xtest/integration/targets/meta_tasks/runme.sh1
3 files changed, 14 insertions, 1 deletions
diff --git a/changelogs/fragments/71355_execute_meta_skip_reason.yml b/changelogs/fragments/71355_execute_meta_skip_reason.yml
new file mode 100644
index 0000000000..f57b785ae3
--- /dev/null
+++ b/changelogs/fragments/71355_execute_meta_skip_reason.yml
@@ -0,0 +1,2 @@
+minor_changes:
+ - meta - now include a ``skip_reason`` when skipped (https://github.com/ansible/ansible/pull/71355).
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 726e84e6aa..47ed859160 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -1138,6 +1138,7 @@ class StrategyBase:
skipped = False
msg = ''
+ skip_reason = '%s conditional evaluated to False' % meta_action
self._tqm.send_callback('v2_playbook_on_task_start', task, is_conditional=False)
# These don't support "when" conditionals
@@ -1163,6 +1164,7 @@ class StrategyBase:
msg = "facts cleared"
else:
skipped = True
+ skip_reason += ', not clearing facts and fact cache for %s' % target_host.name
elif meta_action == 'clear_host_errors':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
@@ -1172,6 +1174,7 @@ class StrategyBase:
msg = "cleared host errors"
else:
skipped = True
+ skip_reason += ', not clearing host error state for %s' % target_host.name
elif meta_action == 'end_play':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
@@ -1180,6 +1183,7 @@ class StrategyBase:
msg = "ending play"
else:
skipped = True
+ skip_reason += ', continuing play'
elif meta_action == 'end_host':
if _evaluate_conditional(target_host):
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
else:
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
elif meta_action == 'reset_connection':
all_vars = self._variable_manager.get_vars(play=iterator._play, host=target_host, task=task,
@@ -1233,12 +1239,16 @@ class StrategyBase:
result = {'msg': msg}
if skipped:
result['skipped'] = True
+ result['skip_reason'] = skip_reason
else:
result['changed'] = False
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):
''' returns list of available hosts for this iterator by filtering out unreachables '''
diff --git a/test/integration/targets/meta_tasks/runme.sh b/test/integration/targets/meta_tasks/runme.sh
index b617965df4..b8defed26d 100755
--- a/test/integration/targets/meta_tasks/runme.sh
+++ b/test/integration/targets/meta_tasks/runme.sh
@@ -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: 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 -qv "play not ended for testhost2" <<< "$out"
done