Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added connect_params to allow any additional parameters that libpg understands #329

Merged
merged 19 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- postgresql_* - add the ``connect_params`` parameter dict to allow any additional ``libpg`` connection parameters (https://github.com/ansible-collections/community.postgresql/pull/329).
6 changes: 6 additions & 0 deletions plugins/doc_fragments/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class ModuleDocFragment(object):
- If the file exists, the server's certificate will be verified to be signed by one of these authorities.
type: str
aliases: [ ssl_rootcert ]
connect_params:
description:
- Any additional parameters to be passed to libpg.
- These parameters take precedence.
type: dict
version_added: '2.3.0'
notes:
- The default authentication assumes that you are either logging in as or sudo'ing to the C(postgres) account on the host.
- To avoid "Peer authentication failed for user postgres" error,
Expand Down
7 changes: 6 additions & 1 deletion plugins/module_utils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def postgres_common_argument_spec():
port=dict(type='int', default=5432, aliases=['login_port']),
ssl_mode=dict(default='prefer', choices=['allow', 'disable', 'prefer', 'require', 'verify-ca', 'verify-full']),
ca_cert=dict(aliases=['ssl_rootcert']),
connect_params=dict(default={}, type='dict'),
)


Expand Down Expand Up @@ -185,7 +186,7 @@ def get_conn_params(module, params_dict, warn_db_default=True):
"login_password": "password",
"port": "port",
"ssl_mode": "sslmode",
"ca_cert": "sslrootcert"
"ca_cert": "sslrootcert",
}

# Might be different in the modules:
Expand Down Expand Up @@ -223,6 +224,10 @@ def get_conn_params(module, params_dict, warn_db_default=True):
if is_localhost and params_dict["login_unix_socket"] != "":
kw["host"] = params_dict["login_unix_socket"]

# If connect_params is specified, merge it together
if params_dict.get("connect_params"):
kw.update(params_dict["connect_params"])

return kw


Expand Down
11 changes: 11 additions & 0 deletions plugins/modules/postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@
db: test_db
query: INSERT INTO test_table (id, story) VALUES (2, 'my_long_story')

- name: Use connect_params to add any additional connection parameters that libpg supports
community.postgresql.postgresql_query:
connect_params:
target_session_attrs: read-write
connect_timeout: 10
login_host: "host1,host2"
login_user: "test"
login_password: "test1234"
db: 'test'
query: 'insert into test (test) values (now())'


# WARNING: The path_to_script and as_single_query options have been deprecated
# and will be removed in community.postgresql 3.0.0, please
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
pg_parameters: &pg_parameters
login_user: '{{ pg_user }}'
login_db: '{{ db_default }}'
connect_params:
connect_timeout: 30


block:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
pg_parameters: &pg_parameters
login_user: '{{ pg_user }}'
login_db: '{{ test_db }}'
connect_params:
connect_timeout: 30

block:
- name: Create test db
Expand Down
Loading