diff options
author | binary <me@rgoncalves.se> | 2021-01-22 21:47:43 +0100 |
---|---|---|
committer | binary <me@rgoncalves.se> | 2021-01-22 21:47:43 +0100 |
commit | 3ee51178ccf8b4ed610da788efe757b633125331 (patch) | |
tree | 077f64ffcd4f25f1125c0845d83b391699b80516 /roles/postgres/tasks | |
parent | 4fed8e0a3e439f39f0f187bfb899ed33819e2d18 (diff) | |
download | infrastructure-3ee51178ccf8b4ed610da788efe757b633125331.tar.gz |
Add postgres initialization
Diffstat (limited to 'roles/postgres/tasks')
-rw-r--r-- | roles/postgres/tasks/main.yml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml index e032ff5..2413b03 100644 --- a/roles/postgres/tasks/main.yml +++ b/roles/postgres/tasks/main.yml @@ -4,9 +4,55 @@ --- +- name: ensure postgres is installed for OpenBSD + package: name=postgresql-server state=present + when: ansible_distribution == "OpenBSD" + - 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: ensure postgres directory exists + file: + path: "{{ postgres_dir }}" + owner: "{{ postgres_user }}" + group: "{{ postgres_group }}" + mode: 0760 + state: directory + +- name: delete default data dir if exists + file: path=/var/postgresql state=absent + when: postgres_dir != "/var/postgresql" + +- name: link postgres directory to default one + file: + src: "{{ postgres_dir }}" + dest: "/var/postgresql" + owner: "{{ postgres_user }}" + group: "{{ postgres_group }}" + state: link + mode: 0760 + when: postgres_dir != "/var/postgresql" + +- 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 + 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 - name: enable and restart postgres service service: |