Skip to content

Commit

Permalink
Add vardef exports for postgres os user and group (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Mar 20, 2024
1 parent f7d5056 commit ec3767d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
26 changes: 13 additions & 13 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
- name: Create PostgreSQL data directory
ansible.builtin.file:
path: "{{ _postgresql_datadir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
state: directory
mode: 0700

Expand All @@ -46,7 +46,7 @@
cmd: "{{ _postgresql_bindir }}/initdb -D {{ _postgresql_datadir }}"
creates: "{{ _postgresql_datadir }}/PG_VERSION"
become: true
become_user: "{{ postgresql_user }}"
become_user: "{{ _postgresql_user }}"
when: _postgresql_initdb | bool

- name: Enable PostgreSQL checksums
Expand All @@ -59,16 +59,16 @@
ansible.builtin.file:
path: "{{ _postgresql_conf_include }}"
state: directory
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
mode: 0755

- name: Manage PostgreSQL ansible include config
ansible.builtin.copy:
dest: "{{ _postgresql_conf_ansible }}"
content: "{{ postgresql_conf_ansible }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
mode: 0644
when: postgresql_conf_ansible is defined
notify: postgresql_reload
Expand All @@ -85,8 +85,8 @@
path: "{{ _postgresql_conf_local }}"
state: touch
modification_time: preserve
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
mode: 0644
changed_when: false

Expand All @@ -106,8 +106,8 @@
ansible.builtin.template:
src: postgresql.conf.j2
dest: "{{ _postgresql_conf_main }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
backup: true
mode: 0644
notify: postgresql_restart
Expand All @@ -116,8 +116,8 @@
ansible.builtin.template:
src: pg_hba.conf.j2
dest: "{{ _postgresql_conf_hba }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
owner: "{{ _postgresql_user }}"
group: "{{ _postgresql_group }}"
backup: true
mode: 0644
vars:
Expand Down
6 changes: 3 additions & 3 deletions tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
encoding: "{{ item.encoding | default('UTF-8') }}"
template: "{{ item.template | default('template0') }}"
port: "{{ item.port | default(omit) }}"
owner: "{{ item.owner | default(postgresql_user) }}"
owner: "{{ item.owner | default(_postgresql_user) }}"
state: "{{ item.state | default('present') }}"
loop_control:
label: "{{ item.name }}"
loop: "{{ postgresql_databases }}"
become: true
become_user: "{{ postgresql_user }}"
become_user: "{{ _postgresql_user }}"

- name: Manage PostgreSQL database privileges
community.postgresql.postgresql_privs:
Expand All @@ -38,6 +38,6 @@
label: "{{ _database.name }}"
loop: "{{ postgresql_databases | subelements('roles', skip_missing='yes') }}"
become: true
become_user: "{{ postgresql_user }}"
become_user: "{{ _postgresql_user }}"
environment:
PGOPTIONS: "{{ _postgresql_pgoptions }}"
4 changes: 2 additions & 2 deletions tasks/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
label: "{{ item.name }}"
loop: "{{ postgresql_roles }}"
become: true
become_user: "{{ postgresql_user }}"
become_user: "{{ _postgresql_user }}"
environment:
PGOPTIONS: "{{ _postgresql_pgoptions }}"
no_log: "{{ postgresql_nolog }}"
Expand All @@ -29,7 +29,7 @@
label: "{{ _role.name }} - {{ _group_name }} - {{ _group_state }}"
loop: "{{ postgresql_roles | subelements('groups', skip_missing='yes') }}"
become: true
become_user: "{{ postgresql_user }}"
become_user: "{{ _postgresql_user }}"
environment:
PGOPTIONS: "{{ _postgresql_pgoptions }}"
no_log: "{{ postgresql_nolog }}"
2 changes: 2 additions & 0 deletions tasks/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
ansible.builtin.set_fact:
_postgresql_package_name: "{{ postgresql_package_name | default(_default_package_name) }}"
_postgresql_service_name: "{{ postgresql_service_name | default(_default_service) }}"
_postgresql_user: "{{ postgresql_user }}"
_postgresql_group: "{{ postgresql_group }}"
_postgresql_bindir: "{{ __postgresql_bindir | nephelaiio.plugins.sorted_get(_conf_search) }}"
_postgresql_confdir: "{{ _conf_confdir }}"
_postgresql_datadir: "{{ _conf_datadir }}"
Expand Down

0 comments on commit ec3767d

Please sign in to comment.