postgresql modules: use postgres.exec_sql instead of __exec_sql methods (#57674)

* postgresql modules: use postgres.exec_sql instead of __exec_sql methods

* postgresql modules: use exec_sql, added changelog fragment

* Update changelogs/fragments/57674-postgres_modules_use_exec_sql_instead_of_methods.yml

Co-Authored-By: Felix Fontein <felix@fontein.de>
This commit is contained in:
Andrey Klychkov
2019-06-11 14:42:53 +03:00
committed by Felix Fontein
parent f80ac73316
commit a8ebbecd53
7 changed files with 73 additions and 158 deletions

View File

@@ -80,7 +80,11 @@ except ImportError:
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.database import SQLParseError
from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec
from ansible.module_utils.postgres import (
connect_to_db,
exec_sql,
postgres_common_argument_spec,
)
from ansible.module_utils._text import to_native
from ansible.module_utils.six import iteritems
@@ -103,7 +107,7 @@ class PgPing(object):
def get_pg_version(self):
query = "SELECT version()"
raw = self.__exec_sql(query)[0][0]
raw = exec_sql(self, query, add_to_executed=False)[0][0]
if raw:
self.is_available = True
raw = raw.split()[1].split('.')
@@ -112,16 +116,6 @@ class PgPing(object):
minor=int(raw[1]),
)
def __exec_sql(self, query):
try:
self.cursor.execute(query)
res = self.cursor.fetchall()
if res:
return res
except Exception as e:
self.module.fail_json("Unable to execute '%s': %s" % (query, to_native(e)))
return False
# ===========================================
# Module execution.