Skip to content

feature request: bulk option for pg_hba module #297

@betanummeric

Description

@betanummeric

feature idea for module postgresql_pg_hba: bulk rule editing

Some of my pg_hba.conf have over 700 managed rules, which takes some time and memory to loop over (repeated parsing, editing and writing). My current usecase looks like this:

- name: manage pg_hba.conf
  community.postgresql.postgresql_pg_hba:
    create: yes
    dest: "{{ data_dir }}/pg_hba.conf"
    backup: yes
    backup_file: "{{ data_dir }}/pg_hba.conf.ansible_backup"
    keep_comments_at_rules: true
   # not used here: attributes, group, mode, owner, selevel, serole, setype, seuser, unsafe_writes

    contype: "{{ entry.host }}"
    method: "{{ entry.method }}"
    options: "{{ entry.options }}"
    address: "{{ entry.address }}"
    netmask: "{{ entry.netmask }}"
    databases: "{{ entry.databases }}"
    state: "{{ entry.state }}"
    users: "{{ entry.users }}"
    comment: "{{ entry.comment }}"
  loop: "{{ desired_state.pghba|default([]) }}"
  loop_control:
    loop_var: entry

I would like to optimize that by adding/removing multiple rules with a single call to the module, which could look like this:

- name: manage pg_hba.conf
  community.postgresql.postgresql_pg_hba:
    create: yes
    dest: "{{ data_dir }}/pg_hba.conf"
    backup: yes
    backup_file: "{{ data_dir }}/pg_hba.conf.ansible_backup"
    keep_comments_at_rules: true
   # not used here: attributes, group, mode, owner, selevel, serole, setype, seuser, unsafe_writes

    bulk: "{{ desired_state.pghba|default([]) }}"

The new bulk argument (or rules?) would take a list of objects, each specifying a rule using the existing arguments:

address
comment
contype
databases
method
netmask
options
state
users

If one object is missing one of these, the default is taken, if possible.

When the arguments which can be put into the bulk argument are set normally (example below), they could either

  1. connflict with the bulk argument
  2. be appended to the bulk argument
  3. be treated as defaults for missing values in the bulk argument
- name: manage pg_hba.conf
  community.postgresql.postgresql_pg_hba:
    contype: host
    address: "2001:db8:1::/64"
    databases: db1
    users: user1
    state: absent

    bulk:
    - contype: host
      address: "2001:db8:2::/64"
      databases: db2
      users: user2
# option 1 would let the module fail

# option 2 would be equivalent to:
- name: manage pg_hba.conf
  community.postgresql.postgresql_pg_hba:
    bulk:
    - contype: host
      address: "2001:db8:1::/64"
      databases: db1
      users: user1
      state: absent
    - contype: host
      address: "2001:db8:2::/64"
      databases: db2
      users: user2
      # implicit "state: present"

# option 3 would be equivalent to:
- name: manage pg_hba.conf
  community.postgresql.postgresql_pg_hba:
    bulk:
    - contype: host
      address: "2001:db8:2::/64"
      databases: db2
      users: user2
      state: absent  # normal "state" argument used as default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions