mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
ISSUE-37945 output not populated on failure (#37952)
* ISSUE-37945 output not populated on failure This always includes output, but it is empty on failure. * handle the other failcases as well
This commit is contained in:
parent
62c2b9a544
commit
509f52a8ed
1 changed files with 9 additions and 6 deletions
|
@ -115,7 +115,7 @@ def is_csrf_protection_enabled(module):
|
||||||
module.params['url'] + '/api/json',
|
module.params['url'] + '/api/json',
|
||||||
method='GET')
|
method='GET')
|
||||||
if info["status"] != 200:
|
if info["status"] != 200:
|
||||||
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
|
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')
|
||||||
|
|
||||||
content = to_native(resp.read())
|
content = to_native(resp.read())
|
||||||
return json.loads(content).get('useCrumbs', False)
|
return json.loads(content).get('useCrumbs', False)
|
||||||
|
@ -126,7 +126,7 @@ def get_crumb(module):
|
||||||
module.params['url'] + '/crumbIssuer/api/json',
|
module.params['url'] + '/crumbIssuer/api/json',
|
||||||
method='GET')
|
method='GET')
|
||||||
if info["status"] != 200:
|
if info["status"] != 200:
|
||||||
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
|
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')
|
||||||
|
|
||||||
content = to_native(resp.read())
|
content = to_native(resp.read())
|
||||||
return json.loads(content)
|
return json.loads(content)
|
||||||
|
@ -148,14 +148,17 @@ def main():
|
||||||
|
|
||||||
if module.params['user'] is not None:
|
if module.params['user'] is not None:
|
||||||
if module.params['password'] is None:
|
if module.params['password'] is None:
|
||||||
module.fail_json(msg="password required when user provided")
|
module.fail_json(msg="password required when user provided", output='')
|
||||||
module.params['url_username'] = module.params['user']
|
module.params['url_username'] = module.params['user']
|
||||||
module.params['url_password'] = module.params['password']
|
module.params['url_password'] = module.params['password']
|
||||||
module.params['force_basic_auth'] = True
|
module.params['force_basic_auth'] = True
|
||||||
|
|
||||||
if module.params['args'] is not None:
|
if module.params['args'] is not None:
|
||||||
from string import Template
|
from string import Template
|
||||||
|
try:
|
||||||
script_contents = Template(module.params['script']).substitute(module.params['args'])
|
script_contents = Template(module.params['script']).substitute(module.params['args'])
|
||||||
|
except KeyError as err:
|
||||||
|
module.fail_json(msg="Error with templating variable: %s" % err, output='')
|
||||||
else:
|
else:
|
||||||
script_contents = module.params['script']
|
script_contents = module.params['script']
|
||||||
|
|
||||||
|
@ -172,12 +175,12 @@ def main():
|
||||||
timeout=module.params['timeout'])
|
timeout=module.params['timeout'])
|
||||||
|
|
||||||
if info["status"] != 200:
|
if info["status"] != 200:
|
||||||
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"])
|
module.fail_json(msg="HTTP error " + str(info["status"]) + " " + info["msg"], output='')
|
||||||
|
|
||||||
result = to_native(resp.read())
|
result = to_native(resp.read())
|
||||||
|
|
||||||
if 'Exception:' in result and 'at java.lang.Thread' in result:
|
if 'Exception:' in result and 'at java.lang.Thread' in result:
|
||||||
module.fail_json(msg="script failed with stacktrace:\n " + result)
|
module.fail_json(msg="script failed with stacktrace:\n " + result, output='')
|
||||||
|
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
output=result,
|
output=result,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue