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

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

merged 19 commits into from
Aug 10, 2022

Conversation

Boosai
Copy link
Contributor

@Boosai Boosai commented Aug 5, 2022

SUMMARY

Added "connect_params" parameter dict to allow any additional libpg connection parameters.

The postgres library "psycopg" used in this module allows to add
any parameters as kwargs.

The dict "connect_params" can be used to pass in any parameters as kwargs to "psycopg".

https://www.psycopg.org/docs/module.html#psycopg2.connect

This is a more generic approach of PR#324.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

postgres_*

Affects all modules that establish a database connection.

ADDITIONAL INFORMATION

The key/values of the connect_params parameter dict is passed unmodified as kwargs to the module.

For example:

There is a cluster setup "host1" and "host2". But we do not know which one
of the hosts is the primary (read-write access) and the secondary
(write-only access). In addition we want to set the connection timeout.
We want to insert some data:

  - 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())

We list both hosts in "login_host" and added
"target_session_attrs=read-write" as additional connection parameter to automatically select the
primary.

(Otherwise we would get "cannot execute INSERT in a read-only
transaction" if "host1" is currently the secondary.)

And we set the connection timeout to 10 seconds.

https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING

@Boosai Boosai marked this pull request as ready for review August 8, 2022 06:55
Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Boosai hi, thanks for the new feature!

Could you also please add the new parameter to any task of any file of any target (say, postgresql_info/tasks/* or postgresql_query/tasks/*) in tests/integration/targets?

plugins/modules/postgresql_query.py Outdated Show resolved Hide resolved
plugins/modules/postgresql_query.py Outdated Show resolved Hide resolved
@Boosai
Copy link
Contributor Author

Boosai commented Aug 10, 2022

Could you also please add the new parameter to any task of any file of any target (say, postgresql_info/tasks/* or postgresql_query/tasks/*) in tests/integration/targets?

@Andersson007, I added "connect_timeout=30" via "connect_param" to any tasks there.

Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Boosai LGTM thanks!

@hunleyd if you're OK with it, feel free to merge

@jchancojr
Copy link
Collaborator

LGTM. Thx, Doug!

Copy link
Collaborator

@jchancojr jchancojr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hunleyd hunleyd merged commit 6de2fa6 into ansible-collections:main Aug 10, 2022
@Andersson007
Copy link
Collaborator

@Boosai thanks for the contribution!
@hunleyd @jchancojr thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants