mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-29 13:51:28 -07:00
postgresql modules: move connect_to_db and get_pg_version to module_utils/postgres.py (#55514)
* postgresql modules: move connect_to_db, get_pg_version to module_utils * postgresql modules: move connect_to_db, get_pg_version to module_utils 2 * postgresql modules: move connect_to_db, get_pg_version to module_utils 3
This commit is contained in:
parent
10b02e17b9
commit
316d1db29f
12 changed files with 51 additions and 217 deletions
|
@ -177,33 +177,11 @@ except ImportError:
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.database import SQLParseError, pg_quote_identifier
|
||||
from ansible.module_utils.postgres import postgres_common_argument_spec
|
||||
from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
||||
def connect_to_db(module, kw, autocommit=False):
|
||||
try:
|
||||
db_connection = psycopg2.connect(**kw)
|
||||
if autocommit:
|
||||
if psycopg2.__version__ >= '2.4.2':
|
||||
db_connection.set_session(autocommit=True)
|
||||
else:
|
||||
db_connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||
|
||||
except TypeError as e:
|
||||
if 'sslrootcert' in e.args[0]:
|
||||
module.fail_json(msg='Postgresql server must be at least '
|
||||
'version 8.4 to support sslrootcert')
|
||||
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e))
|
||||
|
||||
except Exception as e:
|
||||
module.fail_json(msg="unable to connect to database: %s" % to_native(e))
|
||||
|
||||
return db_connection
|
||||
|
||||
|
||||
class PgTablespace(object):
|
||||
def __init__(self, module, cursor, name):
|
||||
self.module = module
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue