Fix kolla_toolbox error handling
Backport only. The kolla_toolbox Ansible module executes as-hoc ansible commands in the kolla_toolbox container, and parses the output to make it look as if ansible-playbook executed the command. Currently however, this module sometimes fails to catch failures of the underlying command, and also sometimes shows tasks as 'ok' when the underlying command was changed. This change introduces a check on the status field for non-JSON output, and assumes the module has changes on success. NOTE: The original patch on master (https://review.opendev.org/#/c/682340/) cannot be backported as it relies on Ansible 2.5+ in the kolla_toolbox container. Change-Id: Ib1e33f8e5c60d98b76a4eba9f405af89431d60bc Closes-Bug: 1844114
This commit is contained in:
parent
ba332d42d4
commit
28273411a8
@ -145,6 +145,7 @@ def main():
|
||||
m = exp.match(output)
|
||||
if m:
|
||||
inner_output = m.groupdict().get('stdout')
|
||||
status = m.groupdict().get('status')
|
||||
break
|
||||
else:
|
||||
module.fail_json(
|
||||
@ -154,7 +155,14 @@ def main():
|
||||
try:
|
||||
ret = json.loads(inner_output)
|
||||
except ValueError:
|
||||
# Some modules (e.g. command) do not produce a JSON output. Instead,
|
||||
# check the status, and assume changed on success.
|
||||
ret['stdout'] = inner_output
|
||||
if status != "SUCCESS":
|
||||
ret['failed'] = True
|
||||
else:
|
||||
# No way to know whether changed - assume yes.
|
||||
ret['changed'] = True
|
||||
|
||||
module.exit_json(**ret)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user