diff options
author | Andrew Klychkov <aaklychkov@mail.ru> | 2020-01-01 13:15:48 +0300 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2020-01-01 05:15:48 -0500 |
commit | f7d412144616f538f2b82a40f2698934d374f7c1 (patch) | |
tree | 7d53a23672c13c71420e81280500d04a019ec09c | |
parent | 80896792c86de71728bf0974f152ec1fb76afd23 (diff) | |
download | ansible-f7d412144616f538f2b82a40f2698934d374f7c1.tar.gz |
postgresql_query: refactoring (#66084)
-rw-r--r-- | lib/ansible/modules/database/postgresql/postgresql_query.py | 9 |
1 files 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))) |