From 32ef77d9fdc946d75d7666a9ac5960f6664159b5 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Fri, 19 Jun 2020 10:29:54 +0200 Subject: [PATCH] Add more useful information from exception When the module faces API exception we can give much more useful information to the user. Let us do this for the modules inheriting from the base class, since all modules should do this at some point in time Change-Id: I5f1ef01765829900334aa2ecae5dab3ba96f1a49 --- plugins/module_utils/openstack.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/openstack.py b/plugins/module_utils/openstack.py index bece2664..0b618485 100644 --- a/plugins/module_utils/openstack.py +++ b/plugins/module_utils/openstack.py @@ -389,6 +389,14 @@ class OpenStackModule: if results and isinstance(results, dict): self.ansible.exit_json(**results) except self.sdk.exceptions.OpenStackCloudException as e: - self.ansible.fail_json(msg=str(e), extra_data=e.extra_data) + params = { + 'msg': str(e), + 'extra_data': { + 'data': e.extra_data, + 'details': e.details, + 'response': e.response.text + } + } + self.ansible.fail_json(**params) # if we got to this place, modules didn't exit self.ansible.exit_json(**self.results)