From e6811b5ca78e50b76d8fb60ea200dbe7f7277f17 Mon Sep 17 00:00:00 2001 From: jeanmonet Date: Mon, 10 May 2021 10:10:02 -0500 Subject: [PATCH] Fixes #158, #40, #124: Custom Data Directory Fixes #158, #40, #124 allowing for a custom data directory --- tasks/configure.yml | 15 +++++++++++++-- tasks/main.yml | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index df434645..95d4477a 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,8 +1,19 @@ --- -- name: Configure global settings. +# `data_directory` in postgresql.conf set to `postgresql_data_dir` variable +# Can be overridden in next task if `data_directory` parameter is also set +# via `postgresql_global_config_options` var +- name: Configure data dir in postgresql.conf. lineinfile: dest: "{{ postgresql_config_path }}/postgresql.conf" - regexp: "^#?{{ item.option }}.+$" + regexp: "^#?\\s*data_directory\\s*=.+$" + line: "data_directory = '{{ postgresql_data_dir }}'" + mode: 0644 + notify: restart postgresql + +- name: Configure global settings (postgresql.conf). + lineinfile: + dest: "{{ postgresql_config_path }}/postgresql.conf" + regexp: "^#?\\s*{{ item.option }}\\s*=.+$" line: "{{ item.option }} = '{{ item.value }}'" state: "{{ item.state | default('present') }}" mode: 0644 diff --git a/tasks/main.yml b/tasks/main.yml index ef531228..d9165079 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,6 +15,11 @@ - include_tasks: initialize.yml - include_tasks: configure.yml +# Otherwise users and db are created in default data dir location (Ubunut: /var/lib/postgresql/...) +# instead of the custom `postgresql_data_dir` +- name: Reset Ansible handlers to ensure users and db are created in data dir {{ postgresql_data_dir }} + meta: flush_handlers + - name: Ensure PostgreSQL is started and enabled on boot. service: name: "{{ postgresql_daemon }}"