diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 84d4fb5142..a111a6db68 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -22,6 +22,7 @@ __metaclass__ = type import json import difflib import warnings +from copy import deepcopy from six import string_types @@ -100,6 +101,21 @@ class CallbackBase: except UnicodeDecodeError: return ">> the files are different, but the diff library cannot compare unicode strings" + def _process_items(self, result): + + for res in result._result['results']: + import q + q(res) + + newres = deepcopy(result) + newres._result = res + if 'failed' in res and res['failed']: + self.v2_runner_on_failed(newres) + else: + self.v2_runner_on_ok(newres) + + del result._result['results'] + def set_play_context(self, play_context): pass diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py index c56e300468..1f9179d84a 100644 --- a/lib/ansible/plugins/callback/default.py +++ b/lib/ansible/plugins/callback/default.py @@ -46,6 +46,9 @@ class CallbackModule(CallbackBase): # finally, remove the exception from the result so it's not shown every time del result._result['exception'] + if result._task.loop and 'results' in result._result: + self._process_items(result) + self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red') if result._task.ignore_errors: @@ -63,6 +66,9 @@ class CallbackModule(CallbackBase): msg = "ok: [%s]" % result._host.get_name() color = 'green' + if result._task.loop and 'results' in result._result: + self._process_items(result) + if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result and result._task.action != 'include': msg += " => %s" % self._dump_results(result._result) self._display.display(msg, color=color)