diff --git a/README.md b/README.md index a30ec22..70c86cf 100644 --- a/README.md +++ b/README.md @@ -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 } diff --git a/defaults/main.yml b/defaults/main.yml index 4e16779..104dd1b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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. diff --git a/tasks/initialize.yml b/tasks/initialize.yml index 0183121..8636a40 100644 --- a/tasks/initialize.yml +++ b/tasks/initialize.yml @@ -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 diff --git a/tasks/variables.yml b/tasks/variables.yml index d655c41..e9b8fa5 100644 --- a/tasks/variables.yml +++ b/tasks/variables.yml @@ -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("/")