From 0f3d2830181d5207b3c50dd4489760149fb6cda3 Mon Sep 17 00:00:00 2001 From: John Gibson <94642752+JohnAtOlo@users.noreply.github.com> Date: Mon, 24 Apr 2023 03:53:08 -0400 Subject: [PATCH] Fix connect_params being ignored (#451) (#455) (cherry picked from commit bbb325758ec4cba98e731a3d72dace3c3b3ac2d3) --- ...gresql_privs_fix_connect_params_being_ignored.yml | 2 ++ plugins/modules/postgresql_privs.py | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/451-postgresql_privs_fix_connect_params_being_ignored.yml diff --git a/changelogs/fragments/451-postgresql_privs_fix_connect_params_being_ignored.yml b/changelogs/fragments/451-postgresql_privs_fix_connect_params_being_ignored.yml new file mode 100644 index 00000000..c9b1dedb --- /dev/null +++ b/changelogs/fragments/451-postgresql_privs_fix_connect_params_being_ignored.yml @@ -0,0 +1,2 @@ +bugfixes: +- postgresql_privs - fix connect_params being ignored (https://github.com/ansible-collections/community.postgresql/issues/450). diff --git a/plugins/modules/postgresql_privs.py b/plugins/modules/postgresql_privs.py index 7bf1353f..5084b654 100644 --- a/plugins/modules/postgresql_privs.py +++ b/plugins/modules/postgresql_privs.py @@ -453,7 +453,7 @@ pg_quote_identifier, check_input, ) -from ansible_collections.community.postgresql.plugins.module_utils.postgres import postgres_common_argument_spec +from ansible_collections.community.postgresql.plugins.module_utils.postgres import postgres_common_argument_spec, get_conn_params from ansible.module_utils._text import to_native VALID_PRIVS = frozenset(('SELECT', 'INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', @@ -518,19 +518,13 @@ def __init__(self, params, module): "ca_cert": "sslrootcert" } - kw = dict((params_map[k], getattr(params, k)) for k in params_map - if getattr(params, k) != '' and getattr(params, k) is not None) - - # If a unix_socket is specified, incorporate it here. - is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost" - if is_localhost and params.unix_socket != "": - kw["host"] = params.unix_socket + conn_params = get_conn_params(module, module.params, warn_db_default=False) sslrootcert = params.ca_cert if psycopg2.__version__ < '2.4.3' and sslrootcert is not None: raise ValueError('psycopg2 must be at least 2.4.3 in order to user the ca_cert parameter') - self.connection = psycopg2.connect(**kw) + self.connection = psycopg2.connect(**conn_params) self.cursor = self.connection.cursor() self.pg_version = self.connection.server_version