From b232b894c3cbe087c8d504e91637dcf62199eed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Thu, 29 Jul 2021 17:00:20 +0200 Subject: Bump to third revision of homelab --- roles/postgres/defaults/main.yml | 5 +++++ roles/postgres/tasks/create_db.yml | 4 ++++ roles/postgres/tasks/create_user.yml | 4 ++++ roles/postgres/tasks/main.yml | 31 ++++++++----------------------- roles/postgres/vars/main.yml | 10 ---------- 5 files changed, 21 insertions(+), 33 deletions(-) create mode 100644 roles/postgres/defaults/main.yml create mode 100644 roles/postgres/tasks/create_db.yml create mode 100644 roles/postgres/tasks/create_user.yml delete mode 100644 roles/postgres/vars/main.yml (limited to 'roles/postgres') diff --git a/roles/postgres/defaults/main.yml b/roles/postgres/defaults/main.yml new file mode 100644 index 0000000..b0c52df --- /dev/null +++ b/roles/postgres/defaults/main.yml @@ -0,0 +1,5 @@ +postgres_dir: /data/postgresql +postgres_default_dir: /var/postgresql +postgres_user: _postgresql +postgres_group: _postgresql +postgres_dbuser: postgres diff --git a/roles/postgres/tasks/create_db.yml b/roles/postgres/tasks/create_db.yml new file mode 100644 index 0000000..9adb6ee --- /dev/null +++ b/roles/postgres/tasks/create_db.yml @@ -0,0 +1,4 @@ +- name: ensure miniflux database exists + shell: createdb -U postgres -O "{{ postgres_db_user }}" "{{ postgres_db_name }}" + register: result + failed_when: result.rc != 0 and "already exists" not in result.stderr diff --git a/roles/postgres/tasks/create_user.yml b/roles/postgres/tasks/create_user.yml new file mode 100644 index 0000000..123070d --- /dev/null +++ b/roles/postgres/tasks/create_user.yml @@ -0,0 +1,4 @@ +- name: ensure miniflux db user exists + shell: createuser -U postgres "{{ postgres_db_user }}" + register: result + failed_when: result.rc != 0 and "already exists" not in result.stderr diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml index 16fce30..80d7aad 100644 --- a/roles/postgres/tasks/main.yml +++ b/roles/postgres/tasks/main.yml @@ -4,34 +4,14 @@ --- -- name: ensure postgres is installed for OpenBSD +- name: ensure postgres is installed package: name: "{{ item }}" state: present - when: ansible_distribution == "OpenBSD" loop: - "postgresql-server" - "postgresql-contrib" -- name: ensure postgres is installed - package: name=postgresql state=present - ignore_errors: true - when: ansible_distribution != "OpenBSD" - -- name: ensure postgres group exists - group: name="{{ postgres_group }}" state=present - -- name: ensure postgres user exists - user: - name: "{{ postgres_user }}" - group: "{{ postgres_group }}" - system: true - state: present - -- 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 }}/{{ item }}" @@ -43,10 +23,16 @@ - "" - "data" +- name: delete default data dir if exists + file: + path: "{{ postgres_default_dir }}" + state: absent + when: postgres_dir != "/var/postgresql" + - name: link postgres directory to default one file: src: "{{ postgres_dir }}" - dest: "/var/postgresql" + dest: "{{ postgres_default_dir }}" owner: "{{ postgres_user }}" group: "{{ postgres_group }}" state: link @@ -57,7 +43,6 @@ # NOTE: this tasks needs `pipelining` set to `false` to work correctly - name: init postgres database shell: | - initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_dbuser }}" --encoding=UTF-8 --locale=en_US.UTF-8 {# --auth=scram-sha-256 --pwprompt #} su - _postgresql -c \ 'initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_dbuser }}" \ --encoding=UTF-8 \ diff --git a/roles/postgres/vars/main.yml b/roles/postgres/vars/main.yml deleted file mode 100644 index 55d977b..0000000 --- a/roles/postgres/vars/main.yml +++ /dev/null @@ -1,10 +0,0 @@ - -# postgres ~~ roles/postgres/tasks/main.yml -# postgres variables - ---- - -postgres_dir: /data/postgres -postgres_user: _postgresql -postgres_group: _postgresql -postgres_dbuser: postgres -- cgit v1.2.3