From c4f1db12ef9fa635bc62d437715e763b3cef312a Mon Sep 17 00:00:00 2001 From: binary Date: Mon, 15 Mar 2021 20:26:50 +0100 Subject: Fix various init and base directory setup. --- roles/postgres/tasks/main.yml | 33 ++++++++++++++++++++++----------- roles/postgres/vars/main.yml | 3 ++- 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'roles') diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml index 2413b03..ecf8e5f 100644 --- a/roles/postgres/tasks/main.yml +++ b/roles/postgres/tasks/main.yml @@ -5,8 +5,13 @@ --- - name: ensure postgres is installed for OpenBSD - package: name=postgresql-server state=present + package: + name: "{{ item }}" + state: present when: ansible_distribution == "OpenBSD" + loop: + - "postgresql-server" + - "postgresql-contrib" - name: ensure postgres is installed package: name=postgresql state=present @@ -23,17 +28,20 @@ system: true state: present -- name: ensure postgres directory exists +- name: delete default data dir if exists + file: path=/var/postgresql state=absent + when: postgres_dir != "/var/postgresql" + +- name: ensure postgres directories exists file: - path: "{{ postgres_dir }}" + path: "{{ postgres_dir }}/{{ item }}" owner: "{{ postgres_user }}" group: "{{ postgres_group }}" - mode: 0760 + mode: "0750" state: directory - -- name: delete default data dir if exists - file: path=/var/postgresql state=absent - when: postgres_dir != "/var/postgresql" + loop: + - "" + - "data" - name: link postgres directory to default one file: @@ -42,17 +50,20 @@ owner: "{{ postgres_user }}" group: "{{ postgres_group }}" state: link - mode: 0760 + mode: "0750" + follow: false when: postgres_dir != "/var/postgresql" + # NOTE: this tasks needs `pipelining` set to `false` to work correctly - name: init postgres database - shell: initdb -D "{{ postgres_dir }}/data/" -U postgres --auth=scram-sha-256 --pwprompt --encoding=UTF-8 --locale=xx_XX.UTF-8 + shell: | + initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_dbuser }}" --encoding=UTF-8 --locale=en_US.UTF-8 {# --auth=scram-sha-256 --pwprompt #} args: chdir: "{{ postgres_dir }}" become: true become_user: "{{ postgres_user }}" register: result - failed_when: result.rc != 0 and "exists but is not empty" not in result.stderr + failed_when: result.rc != 0 and result.stderr is defined and "exists but is not empty" not in result.stderr - name: enable and restart postgres service service: diff --git a/roles/postgres/vars/main.yml b/roles/postgres/vars/main.yml index 0e0030b..55d977b 100644 --- a/roles/postgres/vars/main.yml +++ b/roles/postgres/vars/main.yml @@ -4,6 +4,7 @@ --- -postgres_dir: /var/postgres +postgres_dir: /data/postgres postgres_user: _postgresql postgres_group: _postgresql +postgres_dbuser: postgres -- cgit v1.2.3