From 59b9c5f119dd02449b25020c136d7f9f855051c6 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Mon, 30 Apr 2018 20:18:06 +0200 Subject: [PATCH] Fixes 30786 - add server response to the failure (#39371) * Fixes 30786 - add server response to the failure * replace str(e) with to_native(e) according to code review --- lib/ansible/modules/cloud/openstack/os_stack.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_stack.py b/lib/ansible/modules/cloud/openstack/os_stack.py index 1960c70f570..af4fc7908ff 100644 --- a/lib/ansible/modules/cloud/openstack/os_stack.py +++ b/lib/ansible/modules/cloud/openstack/os_stack.py @@ -149,6 +149,7 @@ stack: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module +from ansible.module_utils._text import to_native def _create_stack(module, stack, cloud, shade): @@ -168,7 +169,10 @@ def _create_stack(module, stack, cloud, shade): else: module.fail_json(msg="Failure in creating stack: {0}".format(stack)) except shade.OpenStackCloudException as e: - module.fail_json(msg=str(e)) + if hasattr(e, 'response'): + module.fail_json(msg=to_native(e), response=e.response.json()) + else: + module.fail_json(msg=to_native(e)) def _update_stack(module, stack, cloud, shade): @@ -188,7 +192,10 @@ def _update_stack(module, stack, cloud, shade): module.fail_json(msg="Failure in updating stack: %s" % stack['stack_status_reason']) except shade.OpenStackCloudException as e: - module.fail_json(msg=str(e)) + if hasattr(e, 'response'): + module.fail_json(msg=to_native(e), response=e.response.json()) + else: + module.fail_json(msg=to_native(e)) def _system_state_change(module, stack, cloud): @@ -260,7 +267,7 @@ def main(): module.fail_json(msg='delete stack failed for stack: %s' % name) module.exit_json(changed=changed) except shade.OpenStackCloudException as e: - module.fail_json(msg=str(e)) + module.fail_json(msg=to_native(e)) if __name__ == '__main__':