From 077a2df1d66d400c6b10023e64ab28dfcd36ad4c Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 10 Jun 2017 23:00:22 +0530 Subject: [PATCH] Return exception as string Pyodbc returns exception as Python Exception class, typecast as string for fail_json. Partially fixes: #25010 Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/database/vertica/vertica_configuration.py | 3 ++- lib/ansible/modules/database/vertica/vertica_facts.py | 3 ++- lib/ansible/modules/database/vertica/vertica_role.py | 3 ++- lib/ansible/modules/database/vertica/vertica_schema.py | 3 ++- lib/ansible/modules/database/vertica/vertica_user.py | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/database/vertica/vertica_configuration.py b/lib/ansible/modules/database/vertica/vertica_configuration.py index 318e155c422..f0cd22616fb 100644 --- a/lib/ansible/modules/database/vertica/vertica_configuration.py +++ b/lib/ansible/modules/database/vertica/vertica_configuration.py @@ -89,6 +89,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -198,7 +199,7 @@ def main(): raise except Exception: e = get_exception() - module.fail_json(msg=e) + module.fail_json(msg=to_native(e)) module.exit_json(changed=changed, parameter=parameter_name, ansible_facts={'vertica_configuration': configuration_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_facts.py b/lib/ansible/modules/database/vertica/vertica_facts.py index ae607e5c7f0..ba0dcd3b16d 100644 --- a/lib/ansible/modules/database/vertica/vertica_facts.py +++ b/lib/ansible/modules/database/vertica/vertica_facts.py @@ -81,6 +81,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -278,7 +279,7 @@ def main(): raise except Exception: e = get_exception() - module.fail_json(msg=e) + module.fail_json(msg=to_native(e)) if __name__ == '__main__': diff --git a/lib/ansible/modules/database/vertica/vertica_role.py b/lib/ansible/modules/database/vertica/vertica_role.py index 5f8c06b6535..f0878083c64 100644 --- a/lib/ansible/modules/database/vertica/vertica_role.py +++ b/lib/ansible/modules/database/vertica/vertica_role.py @@ -100,6 +100,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -248,7 +249,7 @@ def main(): raise except Exception: e = get_exception() - module.fail_json(msg=e) + module.fail_json(msg=to_native(e)) module.exit_json(changed=changed, role=role, ansible_facts={'vertica_roles': role_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_schema.py b/lib/ansible/modules/database/vertica/vertica_schema.py index 3a5a5e9b597..0546105a104 100644 --- a/lib/ansible/modules/database/vertica/vertica_schema.py +++ b/lib/ansible/modules/database/vertica/vertica_schema.py @@ -124,6 +124,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -323,7 +324,7 @@ def main(): raise except Exception: e = get_exception() - module.fail_json(msg=e) + module.fail_json(msg=to_native(e)) module.exit_json(changed=changed, schema=schema, ansible_facts={'vertica_schemas': schema_facts}) diff --git a/lib/ansible/modules/database/vertica/vertica_user.py b/lib/ansible/modules/database/vertica/vertica_user.py index 314c9dd42c6..27cb39428de 100644 --- a/lib/ansible/modules/database/vertica/vertica_user.py +++ b/lib/ansible/modules/database/vertica/vertica_user.py @@ -137,6 +137,7 @@ else: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native class NotSupportedError(Exception): @@ -393,7 +394,7 @@ def main(): raise except Exception: e = get_exception() - module.fail_json(msg=e) + module.fail_json(msg=to_native(e)) module.exit_json(changed=changed, user=user, ansible_facts={'vertica_users': user_facts})