diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2021-12-21 18:39:25 +0000 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2021-12-21 18:39:25 +0000 |
commit | 5534eecf07c5feea015d90f6bbe1f7a864758511 (patch) | |
tree | f931cc4276e5f7aff08d141439c1e08f795499d2 /roles | |
parent | a4c3a63cbdb9fde03e827f1b583e6131faba5bc4 (diff) | |
download | rules-5534eecf07c5feea015d90f6bbe1f7a864758511.tar.gz |
roles/postgres: Force initdb to be run as pg user
Diffstat (limited to 'roles')
-rw-r--r-- | roles/postgres/tasks/main.yml | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml index 78f208c..a203574 100644 --- a/roles/postgres/tasks/main.yml +++ b/roles/postgres/tasks/main.yml @@ -33,14 +33,13 @@ follow: false when: postgres_dir != "/var/postgresql" - # NOTE: this tasks needs `pipelining` set to `false` to work correctly - name: init postgres database # noqa: no-changed-when - command: - cmd: initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_db_user }}" --encoding=UTF-8 --locale=en_US.UTF-8 + shell: + cmd: | + su "{{ postgres_user }}" \ + -c 'initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_db_user }}" --encoding=UTF-8 --locale=en_US.UTF-8' chdir: "{{ postgres_dir }}" register: result - become: true - become_user: "{{ postgres_user }}" failed_when: - result.rc != 0 - "'exists but is not empty' not in result.stderr" |