Skip to content

Commit 9be0668

Browse files
committed
refactor: Update Postgres Ansible tasks and data dir
- Standardize Ansible module usage for PostgreSQL configuration files and related tasks. - Update the default PostgreSQL data directory for `initdb` to `/data/pgdata`.
1 parent 4882331 commit 9be0668

File tree

1 file changed

+59
-73
lines changed

1 file changed

+59
-73
lines changed

ansible/tasks/setup-postgres.yml

Lines changed: 59 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -165,73 +165,59 @@
165165
loop_control:
166166
loop_var: 'pg_config_item'
167167

168-
- name: Allow adminapi to write custom config
169-
file:
170-
path: '{{ item }}'
171-
recurse: yes
172-
state: directory
173-
owner: postgres
174-
group: postgres
175-
mode: 0775
176-
with_items:
177-
- '/etc/postgresql'
178-
- '/etc/postgresql-custom'
179-
- '/etc/postgresql-custom/conf.d'
180-
when: debpkg_mode or nixpkg_mode
181-
182-
- name: create placeholder config files
183-
file:
184-
path: '/etc/postgresql-custom/{{ item }}'
185-
state: touch
186-
owner: postgres
187-
group: postgres
188-
mode: 0664
189-
with_items:
190-
- 'generated-optimizations.conf'
191-
- 'custom-overrides.conf'
192-
when: debpkg_mode or nixpkg_mode
193-
194-
# Move Postgres configuration files into /etc/postgresql
195-
# Add postgresql.conf
196-
- name: import postgresql.conf
197-
template:
198-
src: files/postgresql_config/postgresql.conf.j2
199-
dest: /etc/postgresql/postgresql.conf
200-
group: postgres
201-
when: debpkg_mode or nixpkg_mode
202-
203-
# Add pg_hba.conf
204-
- name: import pg_hba.conf
205-
template:
206-
src: files/postgresql_config/pg_hba.conf.j2
207-
dest: /etc/postgresql/pg_hba.conf
208-
group: postgres
209-
when: debpkg_mode or nixpkg_mode
210-
211-
# Add pg_ident.conf
212-
- name: import pg_ident.conf
213-
template:
214-
src: files/postgresql_config/pg_ident.conf.j2
215-
dest: /etc/postgresql/pg_ident.conf
216-
group: postgres
217-
when: debpkg_mode or nixpkg_mode
218-
219-
# Add custom config for read replicas set up
220-
- name: Move custom read-replica.conf file to /etc/postgresql-custom/conf.d/read-replica.conf
221-
ansible.builtin.copy:
222-
src: "files/postgresql_config/conf.d/read-replica.conf"
223-
dest: /etc/postgresql-custom/conf.d/read-replica.conf
224-
mode: 0664
225-
owner: postgres
226-
group: postgres
227-
when: debpkg_mode or nixpkg_mode
228-
229-
# Install extensions before init
230-
- name: Install Postgres extensions
231-
ansible.builtin.import_tasks:
232-
file: 'tasks/setup-docker.yml'
233-
when:
234-
- (debpkg_mode or stage2_nix)
168+
- name: Allow adminapi to write custom config
169+
ansible.builtin.file:
170+
group: postgres
171+
mode: 0775
172+
owner: postgres
173+
path: '{{ item }}'
174+
recurse: yes
175+
state: directory
176+
with_items:
177+
- '/etc/postgresql'
178+
- '/etc/postgresql-custom'
179+
- '/etc/postgresql-custom/conf.d'
180+
181+
- name: create placeholder config files
182+
ansible.builtin.file:
183+
group: postgres
184+
mode: 0664
185+
owner: postgres
186+
path: '/etc/postgresql-custom/{{ item }}'
187+
state: touch
188+
with_items:
189+
- 'generated-optimizations.conf'
190+
- 'custom-overrides.conf'
191+
192+
- name: import postgresql.conf
193+
ansible.builtin.template:
194+
dest: /etc/postgresql/postgresql.conf
195+
group: postgres
196+
src: files/postgresql_config/postgresql.conf.j2
197+
198+
- name: import pg_hba.conf
199+
ansible.builtin.template:
200+
dest: /etc/postgresql/pg_hba.conf
201+
group: postgres
202+
src: files/postgresql_config/pg_hba.conf.j2
203+
204+
- name: import pg_ident.conf
205+
ansible.builtin.template:
206+
dest: /etc/postgresql/pg_ident.conf
207+
group: postgres
208+
src: files/postgresql_config/pg_ident.conf.j2
209+
210+
- name: Move custom read-replica.conf file to /etc/postgresql-custom/conf.d/read-replica.conf
211+
ansible.builtin.copy:
212+
dest: /etc/postgresql-custom/conf.d/read-replica.conf
213+
group: postgres
214+
mode: 0664
215+
owner: postgres
216+
src: "files/postgresql_config/conf.d/read-replica.conf"
217+
218+
- name: Install Postgres extensions
219+
ansible.builtin.import_tasks:
220+
file: 'tasks/setup-docker.yml'
235221

236222
#stage 2 postgres tasks
237223
- name: stage2 postgres tasks
@@ -271,9 +257,9 @@
271257
- initdb
272258
- -o "--allow-group-access"
273259
- -o "--username=supabase_admin"
274-
- -o "-D /var/lib/postgresql/data"
260+
- -o "-D /data/pgdata"
275261
args:
276-
creates: /var/lib/postgresql/data/PG_VERSION
262+
creates: /data/pgdata/PG_VERSION
277263
vars:
278264
ansible_command_timeout: 60
279265
when:
@@ -307,9 +293,9 @@
307293
- initdb
308294
- -o "--allow-group-access"
309295
- -o "--username=supabase_admin"
310-
- -o "-D /var/lib/postgresql/data"
296+
- -o "-D /data/pgdata"
311297
args:
312-
creates: /var/lib/postgresql/data/PG_VERSION
298+
creates: /data/pgdata/PG_VERSION
313299
environment:
314300
LANG: en_US.UTF-8
315301
LANGUAGE: en_US.UTF-8
@@ -335,9 +321,9 @@
335321
- -o "--locale-provider=icu"
336322
- -o "--encoding=UTF-8"
337323
- -o "--icu-locale=en_US.UTF-8"
338-
- -o "-D /var/lib/postgresql/data"
324+
- -o "-D /data/pgdata"
339325
args:
340-
creates: /var/lib/postgresql/data/PG_VERSION
326+
creates: /data/pgdata/PG_VERSION
341327
environment:
342328
LANG: en_US.UTF-8
343329
LANGUAGE: en_US.UTF-8

0 commit comments

Comments
 (0)