diff --git a/lib/ansible/plugins/callback/selective.py b/lib/ansible/plugins/callback/selective.py index 408936eec4f..d0edf46055a 100644 --- a/lib/ansible/plugins/callback/selective.py +++ b/lib/ansible/plugins/callback/selective.py @@ -154,12 +154,12 @@ class CallbackModule(CallbackBase): print("{} {}".format(line, '-' * (line_length - len(line)))) print(self._indent_text(msg, indent_level + 4)) - if diff is not None: + if diff: self._print_diff(diff, indent_level) - if stdout is not None: + if stdout: stdout = colorize(stdout, 'failed') print(self._indent_text(stdout, indent_level + 4)) - if stderr is not None: + if stderr: stderr = colorize(stderr, 'failed') print(self._indent_text(stderr, indent_level + 4)) @@ -174,15 +174,20 @@ class CallbackModule(CallbackBase): def v2_runner_on_ok(self, result, **kwargs): """Run when a task finishes correctly.""" - failed = 'failed' in result._result - unreachable = 'unreachable' in result._result + failed = result._result.get("failed") + unreachable = result._result.get("unreachable") if 'print_action' in result._task.tags or failed or unreachable or \ - self._display.verbosity > 1: + self._display.verbosity > 1: self._print_task() self.last_skipped = False msg = to_text(result._result.get('msg', '')) or\ to_text(result._result.get('reason', '')) + + stderr = [result._result.get('exception', None), + result._result.get('module_stderr', None)] + stderr = "\n".join([e for e in stderr if e]).strip() + self._print_host_or_item(result._host, result._result.get('changed', False), msg, @@ -190,11 +195,15 @@ class CallbackModule(CallbackBase): is_host=True, error=failed or unreachable, stdout=result._result.get('module_stdout', None), - stderr=result._result.get('exception', None), + stderr=stderr.strip(), ) if 'results' in result._result: for r in result._result['results']: failed = 'failed' in r + + stderr = [r.get('exception', None), r.get('module_stderr', None)] + stderr = "\n".join([e for e in stderr if e]).strip() + self._print_host_or_item(r['item'], r.get('changed', False), to_text(r.get('msg', '')), @@ -202,7 +211,7 @@ class CallbackModule(CallbackBase): is_host=False, error=failed, stdout=r.get('module_stdout', None), - stderr=r.get('exception', None), + stderr=stderr.strip(), ) else: self.last_skipped = True