- Fix to return error message back to the module. (#31035)

This commit is contained in:
Kedar K
2017-09-29 17:06:30 +05:30
committed by GitHub
parent bedfd0a5a4
commit 916e6be888
3 changed files with 48 additions and 8 deletions

View File

@@ -150,10 +150,16 @@ class Cli:
if check_rc and rc != 0:
self._module.fail_json(msg=to_text(err, errors='surrogate_then_replace'))
try:
out = self._module.from_json(out)
except ValueError:
out = str(out).strip()
if not check_rc and rc != 0:
try:
out = self._module.from_json(err)
except ValueError:
out = to_text(err, errors='surrogate_then_replace').strip()
else:
try:
out = self._module.from_json(out)
except ValueError:
out = to_text(out, errors='surrogate_then_replace').strip()
responses.append(out)
return responses