From f7d412144616f538f2b82a40f2698934d374f7c1 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Wed, 1 Jan 2020 13:15:48 +0300 Subject: [PATCH] postgresql_query: refactoring (#66084) --- .../modules/database/postgresql/postgresql_query.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/database/postgresql/postgresql_query.py b/lib/ansible/modules/database/postgresql/postgresql_query.py index b0ac546df8..65f8ebcf29 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_query.py +++ b/lib/ansible/modules/database/postgresql/postgresql_query.py @@ -27,7 +27,8 @@ version_added: '2.8' options: query: description: - - SQL query to run. Variables can be escaped with psycopg2 syntax U(http://initd.org/psycopg/docs/usage.html). + - SQL query to run. Variables can be escaped with psycopg2 syntax + U(http://initd.org/psycopg/docs/usage.html). type: str positional_args: description: @@ -256,9 +257,6 @@ def main(): if autocommit and module.check_mode: module.fail_json(msg="Using autocommit is mutually exclusive with check_mode") - if positional_args and named_args: - module.fail_json(msg="positional_args and named_args params are mutually exclusive") - if path_to_script and query: module.fail_json(msg="path_to_script is mutually exclusive with query") @@ -294,6 +292,9 @@ def main(): try: cursor.execute(query, arguments) except Exception as e: + if not autocommit: + db_connection.rollback() + cursor.close() db_connection.close() module.fail_json(msg="Cannot execute SQL '%s' %s: %s" % (query, arguments, to_native(e)))