diff --git a/lib/ansible/modules/database/postgresql/postgresql_info.py b/lib/ansible/modules/database/postgresql/postgresql_info.py index c1d1a0c252a..c35e25b8ef4 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_info.py +++ b/lib/ansible/modules/database/postgresql/postgresql_info.py @@ -473,7 +473,7 @@ try: except ImportError: HAS_PSYCOPG2 = False -from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.database import SQLParseError from ansible.module_utils.postgres import postgres_common_argument_spec from ansible.module_utils._text import to_native @@ -922,10 +922,7 @@ def main(): argument_spec = postgres_common_argument_spec() argument_spec.update( db=dict(type='str', aliases=['login_db']), - port=dict(type='int', default=5432, aliases=['login_port']), filter=dict(type='list'), - ssl_mode=dict(type='str', default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']), - ca_cert=dict(type='str', aliases=['ssl_rootcert']), session_role=dict(type='str'), ) module = AnsibleModule( @@ -934,7 +931,7 @@ def main(): ) if not HAS_PSYCOPG2: - module.fail_json(msg="The python psycopg2 module is required") + module.fail_json(msg=missing_required_lib('psycopg2')) filter_ = module.params["filter"] sslrootcert = module.params["ca_cert"] diff --git a/lib/ansible/modules/database/postgresql/postgresql_lang.py b/lib/ansible/modules/database/postgresql/postgresql_lang.py index aa063c96e11..d7d1a6f56e9 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_lang.py +++ b/lib/ansible/modules/database/postgresql/postgresql_lang.py @@ -174,10 +174,10 @@ import traceback PSYCOPG2_IMP_ERR = None try: import psycopg2 - postgresqldb_found = True + HAS_PSYCOPG2 = True except ImportError: PSYCOPG2_IMP_ERR = traceback.format_exc() - postgresqldb_found = False + HAS_PSYCOPG2 = False from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.postgres import postgres_common_argument_spec @@ -267,7 +267,7 @@ def main(): sslrootcert = module.params["ca_cert"] session_role = module.params["session_role"] - if not postgresqldb_found: + if not HAS_PSYCOPG2: module.fail_json(msg=missing_required_lib('psycopg2'), exception=PSYCOPG2_IMP_ERR) # To use defaults values, keyword arguments must be absent, so diff --git a/lib/ansible/modules/database/postgresql/postgresql_ping.py b/lib/ansible/modules/database/postgresql/postgresql_ping.py index e067f0434e7..f2716847431 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_ping.py +++ b/lib/ansible/modules/database/postgresql/postgresql_ping.py @@ -78,7 +78,7 @@ try: except ImportError: HAS_PSYCOPG2 = False -from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.database import SQLParseError from ansible.module_utils.postgres import postgres_common_argument_spec from ansible.module_utils._text import to_native @@ -142,7 +142,7 @@ def main(): ) if not HAS_PSYCOPG2: - module.fail_json(msg="The python psycopg2 module is required") + module.fail_json(msg=missing_required_lib('psycopg2')) sslrootcert = module.params["ca_cert"] diff --git a/lib/ansible/modules/database/postgresql/postgresql_schema.py b/lib/ansible/modules/database/postgresql/postgresql_schema.py index a29526305fe..88fcc17a7b1 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_schema.py +++ b/lib/ansible/modules/database/postgresql/postgresql_schema.py @@ -218,19 +218,11 @@ def schema_matches(cursor, schema, owner): def main(): argument_spec = postgres_common_argument_spec() argument_spec.update( - login_user=dict(type="str", default="postgres"), - login_password=dict(type="str", default="", no_log=True), - login_host=dict(type="str", default=""), - login_unix_socket=dict(type="str", default=""), - port=dict(type="int", default=5432, aliases=["login_port"]), schema=dict(type="str", required=True, aliases=['name']), owner=dict(type="str", default=""), database=dict(type="str", default="postgres", aliases=["db", "login_db"]), cascade_drop=dict(type="bool", default=False), state=dict(type="str", default="present", choices=["absent", "present"]), - ssl_mode=dict(type="str", default='prefer', choices=[ - 'disable', 'allow', 'prefer', 'require', 'verify-ca', 'verify-full']), - ca_cert=dict(type="str", default=None, aliases=['ssl_rootcert']), session_role=dict(type="str"), ) diff --git a/lib/ansible/modules/database/postgresql/postgresql_set.py b/lib/ansible/modules/database/postgresql/postgresql_set.py index f6dceaddf7c..278c5ff47b2 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_set.py +++ b/lib/ansible/modules/database/postgresql/postgresql_set.py @@ -165,7 +165,7 @@ try: except ImportError: HAS_PSYCOPG2 = False -from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.database import SQLParseError from ansible.module_utils.postgres import postgres_common_argument_spec from ansible.module_utils.six import iteritems @@ -296,9 +296,6 @@ def main(): argument_spec.update( name=dict(type='str', required=True), db=dict(type='str', aliases=['login_db']), - port=dict(type='int', default=5432, aliases=['login_port']), - ssl_mode=dict(type='str', default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']), - ca_cert=dict(type='str', aliases=['ssl_rootcert']), value=dict(type='str'), reset=dict(type='bool'), session_role=dict(type='str'), @@ -309,7 +306,7 @@ def main(): ) if not HAS_PSYCOPG2: - module.fail_json(msg="the python psycopg2 module is required") + module.fail_json(msg=missing_required_lib('psycopg2')) name = module.params["name"] value = module.params["value"] diff --git a/lib/ansible/modules/database/postgresql/postgresql_table.py b/lib/ansible/modules/database/postgresql/postgresql_table.py index 6f5afa63861..70edaa35036 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_table.py +++ b/lib/ansible/modules/database/postgresql/postgresql_table.py @@ -444,9 +444,6 @@ def main(): table=dict(type='str', required=True, aliases=['name']), state=dict(type='str', default="present", choices=["absent", "present"]), db=dict(type='str', default='', aliases=['login_db']), - port=dict(type='int', default=5432, aliases=['login_port']), - ssl_mode=dict(type='str', default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']), - ca_cert=dict(type='str', aliases=['ssl_rootcert']), tablespace=dict(type='str'), owner=dict(type='str'), unlogged=dict(type='bool'), diff --git a/lib/ansible/modules/database/postgresql/postgresql_tablespace.py b/lib/ansible/modules/database/postgresql/postgresql_tablespace.py index c394689ccb3..30cd23a2ebe 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_tablespace.py +++ b/lib/ansible/modules/database/postgresql/postgresql_tablespace.py @@ -347,9 +347,6 @@ def main(): set=dict(type='dict'), rename_to=dict(type='str'), db=dict(type='str', aliases=['login_db']), - port=dict(type='int', default=5432, aliases=['login_port']), - ssl_mode=dict(type='str', default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']), - ca_cert=dict(type='str', aliases=['ssl_rootcert']), session_role=dict(type='str'), )