mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Ensure that command/shell errors are displayed
This fix ensures that if there are specific module errors (in our case the python interpreter was not found) then command and shell returns a proper error. It also fixes a few other imperfections that we noticed during troubleshooting: - Return the real RC if it were available - Improve a dictionary evaluation using .get() - Return an RC of -1 if it is unknown (instead of returning 0) This fixes #18846
This commit is contained in:
@@ -37,7 +37,7 @@ class CallbackModule(CallbackBase):
|
||||
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 = "%s | %s | rc=%s >>\n" % (host, caption, result.get('rc', -1))
|
||||
buf += result.get('stdout','')
|
||||
buf += result.get('stderr','')
|
||||
buf += result.get('msg','')
|
||||
@@ -55,7 +55,7 @@ class CallbackModule(CallbackBase):
|
||||
|
||||
self._display.display(msg, color=C.COLOR_ERROR)
|
||||
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
if result._task.action in C.MODULE_NO_JSON and 'module_stderr' not in result._result:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, "FAILED"), color=C.COLOR_ERROR)
|
||||
else:
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color=C.COLOR_ERROR)
|
||||
|
||||
@@ -38,9 +38,9 @@ class CallbackModule(CallbackBase):
|
||||
stdout = result.get('stdout','').replace('\n', '\\n')
|
||||
if 'stderr' in result and result['stderr']:
|
||||
stderr = result.get('stderr','').replace('\n', '\\n')
|
||||
return "%s | %s | rc=%s | (stdout) %s (stderr) %s" % (hostname, caption, result.get('rc',0), stdout, stderr)
|
||||
return "%s | %s | rc=%s | (stdout) %s (stderr) %s" % (hostname, caption, result.get('rc', -1), stdout, stderr)
|
||||
else:
|
||||
return "%s | %s | rc=%s | (stdout) %s" % (hostname, caption, result.get('rc',0), stdout)
|
||||
return "%s | %s | rc=%s | (stdout) %s" % (hostname, caption, result.get('rc', -1), stdout)
|
||||
|
||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||
if 'exception' in result._result:
|
||||
@@ -51,7 +51,7 @@ class CallbackModule(CallbackBase):
|
||||
else:
|
||||
msg = "An exception occurred during task execution. The full traceback is:\n" + result._result['exception'].replace('\n','')
|
||||
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
if result._task.action in C.MODULE_NO_JSON and 'module_stderr' not in result._result:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'FAILED'), color=C.COLOR_ERROR)
|
||||
else:
|
||||
self._display.display(msg, color=C.COLOR_ERROR)
|
||||
|
||||
Reference in New Issue
Block a user