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

postgresql_pg_hba: bulk rule editing #303

Merged
merged 24 commits into from
Jul 9, 2022

Conversation

betanummeric
Copy link
Member

feature PR, fixes #297

add new arguments to postgresql_pg_hba to edit multiple rules at once

argument rules

A list of objects, specifying a rule for the pg_hba.conf. Each object can have the following keys (the "rule-specific arguments"), which are treated the same as if they were arguments of this module:

  • address
  • comment
  • contype
  • databases
  • method
  • netmask
  • options
  • state
  • users
    See rules_behavior for what happens when one of these keys missing in a rules item.

argument rules_behavior

String, choices: conflict (default), combine.

When conflict, and rules is specified along with at least one normal rule-specific argument, the module fails. This should prevent accidental ambiguous operations. If a rules item is lacking some rule-specific argument, the respective module default is taken.

When combine, the normal rule-specific arguments are treated as fallback values for the content of rules. (They will not add or remove a role on their own.) When a value is neither specified in a rules item nor in the normal rule-specific argument, the module default is taken.

example:

- name: rules with custom defaults
  community.postgresql.postgresql_pg_hba:
    dest: /tmp/pg_hba.conf
    rules_behavior: combine
    databases: db1
    address: 2001:db8::a/64
    rules:
      - users: user1    
      - users: user2
        address: 2001:db8::b/64

# is equivalent to
- name: rules with custom defaults
  community.postgresql.postgresql_pg_hba:
    dest: /tmp/pg_hba.conf
    rules_behavior: combine
    rules:
      - users: user1    
        databases: db1
        address: 2001:db8::a/64
      - users: user2
        databases: db1
        address: 2001:db8::b/64

argument overwrite

Boolean, default: false. When true, all pre-existing rules will be removed from the pg_hba.conf as if they where specified with state: absent.

@betanummeric betanummeric marked this pull request as ready for review June 27, 2022 14:15
@betanummeric
Copy link
Member Author

CI error https://dev.azure.com/ansible/community.postgresql/_build/results?buildId=46440&view=logs&j=3afb8e66-d9f7-51e9-da18-79a477157904&t=4d67c62b-b0be-5cd8-f96d-9a6e13c4a51a&l=226

00:11 ERROR: Found 1 compile issue(s) on python 2.6 which need to be resolved:
00:11 ERROR: plugins/modules/postgresql_pg_hba.py:814:18: SyntaxError: 'address', (100%)

Python 2.6 is EOL for 8 years now, does it still need to be supported by this module?

@hunleyd
Copy link
Collaborator

hunleyd commented Jun 28, 2022

Python 2.6 is EOL for 8 years now, does it still need to be supported by this module?

I would say 'no' but I defer to @Andersson007

@Andersson007
Copy link
Collaborator

I would say 'no' but I defer to @Andersson007

The collection requirements require at least 2.7 support but if there's no good reason to introduce Python 2.6 incompatible changes, i wouldn't do it (though it's only my opinion and we can vote on it if needed).

@hunleyd
Copy link
Collaborator

hunleyd commented Jun 30, 2022

@betanummeric any updates on the remaining failures ?

@betanummeric
Copy link
Member Author

The remaining error message occurs here and says:

The conditional check 'result.results|selectattr('msg', 'in', 'conflict')|length == 0' failed. The error was: no test named 'in'

The test runs in docker image quay.io/ansible/centos7-test-container:2.0.2 with python 2.7.5 and jinja 2.7.2, but the in-test was added in jinja 2.10. Even

result.results|map(attribute='msg')|map('truncate',8,True,'')|select('equalto','conflict')|length == 0

would not work because equalto was added in jina 2.8. I tried some ways but I see no way to perform this check with jinja in that version.
I would like to ignore or skip that check with that version. In the end, it's only testing that the error messages look sensible.

@Andersson007
Copy link
Collaborator

@betanummeric

I would like to ignore or skip that check with that version. In the end, it's only testing that the error messages look sensible.

Skipping or ignoring it with that version sounds OK to me

@betanummeric
Copy link
Member Author

The tests are green, this is ready for review.

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.

@betanummeric thanks for working on this!

I left several general things.
I'm not a user of the module, so would be nice to hear users' / other maintainers' opinions.

@hunleyd @jchancojr do you use the module or do you know someone who uses it and can take a look?

plugins/modules/postgresql_pg_hba.py Outdated Show resolved Hide resolved
plugins/modules/postgresql_pg_hba.py Outdated Show resolved Hide resolved
plugins/modules/postgresql_pg_hba.py Outdated Show resolved Hide resolved
plugins/modules/postgresql_pg_hba.py Show resolved Hide resolved
@hunleyd
Copy link
Collaborator

hunleyd commented Jul 4, 2022

@hunleyd @jchancojr do you use the module or do you know someone who uses it and can take a look?

myself @pgguru and @keithf4 use the module at $dayjob. we can take a look

betanummeric and others added 4 commits July 4, 2022 18:07
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
@Andersson007
Copy link
Collaborator

@hunleyd @jchancojr do you use the module or do you know someone who uses it and can take a look?

myself @pgguru and @keithf4 use the module at $dayjob. we can take a look

Great, thanks! We'll be waiting for you feedback

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
@hunleyd
Copy link
Collaborator

hunleyd commented Jul 9, 2022

does this need backported once merged @Andersson007 ?

@hunleyd hunleyd merged commit 7de6946 into ansible-collections:main Jul 9, 2022
@sebasmannem
Copy link
Contributor

Awesome work guys.
Thanks.

@hunleyd hunleyd mentioned this pull request Jul 18, 2022
@Andersson007
Copy link
Collaborator

Andersson007 commented Jul 25, 2022

does this need backported once merged @Andersson007 ?

@hunleyd no, it doesn't, thanks for reviewing and merging!

@Andersson007
Copy link
Collaborator

@betanummeric thanks for the contribution!

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.

feature request: bulk option for pg_hba module
5 participants