Merge pull request #190 from gdubicki/ensure_log_dir

Ensure that log dir exists
This commit is contained in:
Jeff Geerling 2022-07-11 11:58:32 -05:00 committed by GitHub
commit 31676e6fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 2 deletions

View File

@ -47,8 +47,11 @@ Control the state of the postgresql service and whether it should start at boot
postgresql_global_config_options:
- option: unix_socket_directories
value: '{{ postgresql_unix_socket_directories | join(",") }}'
Global configuration options that will be set in `postgresql.conf`. Note that for RHEL/CentOS 6 (or very old versions of PostgreSQL), you need to at least override this variable and set the `option` to `unix_socket_directory`.
- option: log_directory
value: 'log'
Global configuration options that will be set in `postgresql.conf`.
For PostgreSQL versions older than 9.3 you need to at least override this variable and set the `option` to `unix_socket_directory`.
If you override the value of `option: log_directory` with another path, relative or absolute, then this role will create it for you.
postgresql_hba_entries:
- { type: local, database: all, user: postgres, auth_method: peer }

View File

@ -23,6 +23,8 @@ postgresql_service_enabled: true
postgresql_global_config_options:
- option: unix_socket_directories
value: '{{ postgresql_unix_socket_directories | join(",") }}'
- option: log_directory
value: 'log'
# Host based authentication (hba) entries to be added to the pg_hba.conf. This
# variable's defaults reflect the defaults that come with a fresh installation.

View File

@ -27,3 +27,11 @@
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
vars:
ansible_ssh_pipelining: true
- name: Ensure PostgreSQL log directory exists.
file:
path: "{{ postgresql_effective_log_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
mode: 0700

View File

@ -54,3 +54,19 @@
postgresql_unix_socket_directories_mode: >-
{{ __postgresql_unix_socket_directories_mode | default('02775') }}
when: postgresql_unix_socket_directories_mode is not defined
- name: Define postgresql_log_dir.
set_fact:
# postgresql_global_config_options is an array but its keys are unique, so it can be converted to dict,
# to easily get the value under the 'log_directory' key
postgresql_log_dir: "{{ (postgresql_global_config_options | items2dict(key_name='option', value_name='value')).log_directory }}"
- name: Define postgresql_effective_log_dir, if postgresql_log_dir is absolute
set_fact:
postgresql_effective_log_dir: '{{ postgresql_log_dir }}'
when: postgresql_log_dir is match("/")
- name: Define postgresql_effective_log_dir, if postgresql_log_dir is relative
set_fact:
postgresql_effective_log_dir: '{{ postgresql_data_dir }}/{{ postgresql_log_dir }}'
when: postgresql_log_dir is not match("/")