diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 1ff33205242..a6efc5f5e71 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -229,6 +229,7 @@ DEFAULT_PASSWORD_CHARS = ascii_letters + digits + ".,:-_" # non-configurable things MODULE_REQUIRE_ARGS = ['command', 'shell', 'raw', 'script'] +MODULE_NO_JSON = ['command', 'shell', 'raw'] DEFAULT_BECOME_PASS = None DEFAULT_SUDO_PASS = None DEFAULT_REMOTE_PASS = None diff --git a/lib/ansible/plugins/callback/minimal.py b/lib/ansible/plugins/callback/minimal.py index 8b3ac325eb3..de01d98c6d4 100644 --- a/lib/ansible/plugins/callback/minimal.py +++ b/lib/ansible/plugins/callback/minimal.py @@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.plugins.callback import CallbackBase +from ansible import constants as C class CallbackModule(CallbackBase): @@ -33,6 +34,16 @@ class CallbackModule(CallbackBase): CALLBACK_TYPE = 'stdout' CALLBACK_NAME = 'minimal' + def _command_generic_msg(self, host, result, caption): + ''' output the result of a command run ''' + + buf = "%s | %s | rc=%s >>\n" % (host, caption, result.get('rc',0)) + buf += result.get('stdout','') + buf += result.get('stdout','') + buf += result.get('msg','') + + return buf + "\n" + def v2_runner_on_failed(self, result, ignore_errors=False): if 'exception' in result._result: if self._display.verbosity < 3: @@ -47,11 +58,17 @@ class CallbackModule(CallbackBase): # finally, remove the exception from the result so it's not shown every time del result._result['exception'] - self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red') + if result._task.action in C.MODULE_NO_JSON: + self._display.display(self._command_generic_msg(result._host.get_name(), result._result,"FAILED"), color='red') + else: + self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color='red') def v2_runner_on_ok(self, result): - self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result)), color='green') - self._handle_warnings(result._result) + if result._task.action in C.MODULE_NO_JSON: + self._display.display(self._command_generic_msg(result._host.get_name(), result._result,"SUCCESS"), color='green') + else: + self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result)), color='green') + self._handle_warnings(result._result) def v2_runner_on_skipped(self, result): self._display.display("%s | SKIPPED" % (result._host.get_name()), color='cyan') diff --git a/lib/ansible/plugins/callback/oneline.py b/lib/ansible/plugins/callback/oneline.py index d7e76151b4c..15a8aee3c82 100644 --- a/lib/ansible/plugins/callback/oneline.py +++ b/lib/ansible/plugins/callback/oneline.py @@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.plugins.callback import CallbackBase +from ansible import constants as C class CallbackModule(CallbackBase): @@ -33,6 +34,12 @@ class CallbackModule(CallbackBase): CALLBACK_TYPE = 'stdout' CALLBACK_NAME = 'oneline' + def _command_generic_msg(self, hostname, result, caption): + if 'stderr' in result and result['stderr']: + return "%s | %s | rc=%s | (stdout) %s (stderr) %s" % (hostname, caption, result.get('rc',0), result.get('stdout',''), result.get('stderr','')) + else: + return "%s | %s | rc=%s | (stdout) %s" % (hostname, caption, result.get('rc',0), result.get('stdout','')) + def v2_runner_on_failed(self, result, ignore_errors=False): if 'exception' in result._result: if self._display.verbosity < 3: @@ -42,7 +49,10 @@ class CallbackModule(CallbackBase): else: msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception'].replace('\n','') - self._display.display(msg, color='red') + if result._task.action in C.MODULE_NO_JSON: + self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'FAILED'), color='red') + else: + self._display.display(msg, color='red') # finally, remove the exception from the result so it's not shown every time del result._result['exception'] @@ -50,7 +60,10 @@ class CallbackModule(CallbackBase): self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')), color='red') def v2_runner_on_ok(self, result): - self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')), color='green') + if result._task.action in C.MODULE_NO_JSON: + self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'SUCCESS'), color='green') + else: + self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')), color='green') def v2_runner_on_unreachable(self, result):