Skip to content

Commit

Permalink
Fixes #158, #40, #124: Custom Data Directory
Browse files Browse the repository at this point in the history
Fixes #158, #40, #124 allowing for a custom data directory
  • Loading branch information
jeanmonet authored and misilot committed Feb 21, 2023
1 parent e8db6bb commit ec3e0d4
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 @@ -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 }}"
Expand Down

0 comments on commit ec3e0d4

Please sign in to comment.