summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Timmons <ted@perljam.net>2017-02-16 11:26:40 -0800
committerToshio Kuratomi <a.badger@gmail.com>2017-02-16 11:26:40 -0800
commita0005944368964504aa0557b250040287e2f9449 (patch)
treef926775729cc75b7377c0c6cec52a85f8a598989
parent3ff2c471b2aebaef1db5ab560b38fa9714479392 (diff)
downloadansible-a0005944368964504aa0557b250040287e2f9449.tar.gz
fix failing fail_json call in postgresql_schema (#21495)
fix failing fail_json call in postgresql_schema - Bugfix Pull Request modules/database/postgresql/postgresql_schema ``` 2.3.0 ``` Here's an example of the error that was coming out. Massaged some linebreaks and backslashes to make it more readable: "module_stderr": "Traceback (most recent call last): File "/tmp/ansible_3X05GE/ansible_module_postgresql_schema.py", line 274, in <module> main() File "/tmp/ansible_3X05GE/ansible_module_postgresql_schema.py", line 265, in main module.fail_json(msg="Database query failed: %s" %(text, str(e))) NameError: global name 'text' is not defined ", Now it triggers with the correct exception and shows the traceback. This duplication of str(e) and traceback seems to be the best design pattern. Sample of the new output: An exception occurred during task execution. The full traceback is: Traceback (most recent call last): File "/tmp/ansible_gp4v1Q/ansible_module_postgresql_schema.py", line 254, in main changed = schema_create(cursor, schema, owner) ... return super(DictCursor, self).execute(query, vars) ProgrammingError: permission denied for database schemadb fatal: [localhost]: FAILED! => { "changed": false, "failed": true, ... }, "msg": "Database query failed: permission denied for database schemadb\n"
-rw-r--r--lib/ansible/modules/database/postgresql/postgresql_schema.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/ansible/modules/database/postgresql/postgresql_schema.py b/lib/ansible/modules/database/postgresql/postgresql_schema.py
index af8d8d9506..c14b4e8233 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_schema.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_schema.py
@@ -101,7 +101,6 @@ schema:
sample: "acme"
'''
-
try:
import psycopg2
import psycopg2.extras
@@ -110,6 +109,10 @@ except ImportError:
else:
postgresqldb_found = True
+import traceback
+
+from ansible.module_utils._text import to_native
+
class NotSupportedError(Exception):
pass
@@ -231,7 +234,7 @@ def main():
cursor_factory=psycopg2.extras.DictCursor)
except Exception:
e = get_exception()
- module.fail_json(msg="unable to connect to database: %s" %(text, str(e)))
+ module.fail_json(msg="unable to connect to database: %s" % to_native(e), exception=traceback.format_exc())
try:
if module.check_mode:
@@ -262,7 +265,7 @@ def main():
raise
except Exception:
e = get_exception()
- module.fail_json(msg="Database query failed: %s" %(text, str(e)))
+ module.fail_json(msg="Database query failed: %s" % to_native(e), exception=traceback.format_exc())
module.exit_json(changed=changed, schema=schema)