Skip to content

Commit

Permalink
Fixes bugs geerlingguy#158, geerlingguy#40, geerlingguy#124: Custom D…
Browse files Browse the repository at this point in the history
…ata Directory

Fixes bugs geerlingguy#158, geerlingguy#40, geerlingguy#124 allowing for a custom data directory
  • Loading branch information
jeanmonet authored and misilot committed Jul 19, 2022
1 parent 31676e6 commit 86e0075
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 }}"
Expand Down

0 comments on commit 86e0075

Please sign in to comment.