feat(postgresql): add playbooks to provision users, databases, hba entries and entire client(s)

This commit is contained in:
transcaffeine 2025-04-19 16:21:22 +02:00
parent 3816daa679
commit f9f00d1919
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
5 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,24 @@
---
- import_playbook: finallycoffee.databases.postgresql_user
vars:
postgresql_users:
- name: "{{ postgresql_client_username }}"
password: "{{ postgresql_client_password }}"
- import_playbook: finallycoffee.databases.postgresql_database
vars:
postgresql_databases:
- name: "{{ postgresql_client_database }}"
owner: "{{ postgresql_client_username }}"
encoding: "{{ postgresql_client_database_encoding | default('UTF8', true) }}"
lc_ctype: "{{ postgresql_client_database_lc_ctype | default('en_US.UTF-8', true) }}"
lc_collate: "{{ postgresql_client_database_lc_collate | default('en_US.UTF-8', true) }}"
- import_playbook: finallycoffee.databases.postgresql_host_based_authentication
vars:
postgresql_authentications:
- users: "{{ postgresql_client_username }}"
databases: "{{ postgresql_client_database }}"
contype: "{{ postgresql_client_database_contype | default('local') }}"
method: "{{ postgresql_client_database_auth_method | default('md5') }}"
options: "{{ postgresql_client_options | default(false, true) }}"
address: "{{ postgresql_client_address | default(false, true) }}"
netmask: "{{ postgresql_client_netmask | default(false, true) }}"

View File

@ -0,0 +1,4 @@
---
- import_playbook: finallycoffee.databases.postgresql_user
- import_playbook: finallycoffee.databases.postgresql_database
- import_playbook: finallycoffee.databases.postgresql_host_based_authentication

View File

@ -0,0 +1,26 @@
---
- name: Configure postgresql databases
hosts: "{{ postgresql_hosts | default('postgresql', true) }}"
become: "{{ postgresql_become | default(false, true) }}"
gather_facts: "{{ postgresql_gather_facts | default(false, true) }}"
tasks:
- name: Configure individual postgresql database
community.postgresql.postgresql_db:
name: "{{ postgresql_database.name }}"
owner: "{{ postgresql_database.owner | default(omit) }}"
state: "{{ postgresql_database_state }}"
template: "{{ postgresql_database.template | default(omit, true) }}"
encoding: "{{ postgresql_database.encoding | default(omit, true) }}"
lc_ctype: "{{ postgresql_database.lc_ctype | default(omit, true) }}"
lc_collate: "{{ postgresql_database.lc_collate | default(omit, true) }}"
login_host: "{{ postgresql_connection_host | default(omit, true) }}"
login_port: "{{ postgresql_connection_port | default(omit, true) }}"
login_unix_socket: "{{ postgresql_connection_unix_socket | default(omit, true) }}"
login_user: "{{ postgresql_connection_user | default(omit, true) }}"
login_password: "{{ postgresql_connection_password | default(omit, true) }}"
vars:
postgresql_database_state: "{{ postgresql_database.state | default('present', true) }}"
loop: "{{ postgresql_databases | default([]) }}"
loop_control:
loop_var: postgresql_database
label: "{{ postgresql_database.name }}"

View File

@ -0,0 +1,23 @@
---
- name: Configure postgresql host based authentications
hosts: "{{ postgresql_hosts | default('postgresql', true) }}"
become: "{{ postgresql_become | default(false, true) }}"
gather_facts: "{{ postgresql_gather_facts | default(false, true) }}"
tasks:
- name: Configure individual postgresql host based authentication
community.postgresql.postgresql_pg_hba:
dest: "{{ postgresql_pg_hba_conf_file }}"
users: "{{ postgresql_auth.users | default(omit) }}"
databases: "{{ postgresql_auth.databases | default(omit) }}"
contype: "{{ postgresql_auth.contype }}"
state: "{{ postgresql_auth_state }}"
method: "{{ postgresql_auth.method | default(omit, true) }}"
options: "{{ postgresql_auth.options | default(omit, true) }}"
address: "{{ postgresql_auth.address | default(omit, true) }}"
netmask: "{{ postgresql_auth.netmask | default(omit, true) }}"
vars:
postgresql_auth_state: "{{ postgresql_auth.state | default('present', true) }}"
loop: "{{ postgresql_authentications | default([]) }}"
loop_control:
loop_var: postgresql_auth
label: "{{ postgresql_auth.users }}@{{ postgresql_auth.databases }}"

View File

@ -0,0 +1,24 @@
---
- name: Configure postgresql users
hosts: "{{ postgresql_hosts | default('postgresql', true) }}"
become: "{{ postgresql_become | default(false, true) }}"
gather_facts: "{{ postgresql_gather_facts | default(false, true) }}"
tasks:
- name: Configure individual postgresql user
community.postgresql.postgresql_user:
name: "{{ postgresql_user.name }}"
state: "{{ postgresql_user_state }}"
password: "{{ postgresql_user_password }}"
login_host: "{{ postgresql_connection_host | default(omit, true) }}"
login_port: "{{ postgresql_connection_port | default(omit, true) }}"
login_unix_socket: "{{ postgresql_connection_unix_socket | default(omit, true) }}"
login_user: "{{ postgresql_connection_user | default(omit, true) }}"
login_password: "{{ postgresql_connection_password | default(omit, true) }}"
vars:
postgresql_user_state: "{{ postgresql_user.state | default('present', true) }}"
postgresql_user_password: >-2
{{ (postgresql_user_state != 'absent') | ternary(postgresql_user.password, omit) }}
loop: "{{ postgresql_users | default([]) }}"
loop_control:
loop_var: postgresql_user
label: "{{ postgresql_user.name }}"