Ensure that log dir exists

because Postgres does not create it by itself
if you change it from the default value
This commit is contained in:
Greg Dubicki 2021-09-10 21:30:44 +02:00
parent 07e5687bb4
commit 830d3fc5ce
4 changed files with 31 additions and 1 deletions

View File

@ -47,8 +47,10 @@ 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(",") }}'
- option: log_directory
value: 'log'
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`.
Global configuration options that will be set in `postgresql.conf`. Note that if you override 'log_directory' with another, absolute path, 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

@ -14,6 +14,14 @@
state: directory
mode: 0700
- name: Ensure PostgreSQL log directory exists.
file:
path: "{{ postgresql_effective_log_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
mode: 0700
- name: Check if PostgreSQL database is initialized.
stat:
path: "{{ postgresql_data_dir }}/PG_VERSION"

View File

@ -49,3 +49,21 @@
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_log_dir: "{{ (postgresql_global_config_options | items2dict(key_name='option', value_name='value')).log_directory }}"
- name: Define postgresql_log_dir_is_absolute.
set_fact:
postgresql_log_dir_is_absolute: '{{ postgresql_log_dir | regex_search("^/.*") != "" }}'
- 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_absolute
- name: Define postgresql_effective_log_dir, if not postgresql_log_dir_is_absolute
set_fact:
postgresql_effective_log_dir: '{{ postgresql_data_dir }}/{{ postgresql_log_dir }}'
when: not postgresql_log_dir_is_absolute