aboutsummaryrefslogtreecommitdiffstats
path: root/roles/postgres/tasks/main.yml
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2021-12-12 16:47:23 +0000
committerRomain Gonçalves <me@rgoncalves.se>2021-12-12 16:47:23 +0000
commit04855031e0e3a74b98e59167ba5da91e077dab48 (patch)
treefd03eb9e7c04b5a422753174dccf7b43b1a0ff66 /roles/postgres/tasks/main.yml
parentc7bce9fa368ac4f45e3ca45bc8a03cff547d9cd1 (diff)
downloadrules-04855031e0e3a74b98e59167ba5da91e077dab48.tar.gz
roles: Add postgresql
Diffstat (limited to 'roles/postgres/tasks/main.yml')
-rw-r--r--roles/postgres/tasks/main.yml52
1 files changed, 52 insertions, 0 deletions
diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml
new file mode 100644
index 0000000..d8fe000
--- /dev/null
+++ b/roles/postgres/tasks/main.yml
@@ -0,0 +1,52 @@
+- name: install postgres
+ package:
+ name:
+ - postgresql-server
+ - postgresql-contrib
+ state: present
+
+- name: create postgres directories
+ file:
+ path: "{{ postgres_dir }}/{{ item }}"
+ owner: "{{ postgres_user }}"
+ group: "{{ postgres_group }}"
+ mode: 0750
+ state: directory
+ loop:
+ - ""
+ - "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: "{{ postgres_default_dir }}"
+ owner: "{{ postgres_user }}"
+ group: "{{ postgres_group }}"
+ state: link
+ mode: 0750
+ follow: false
+ when: postgres_dir != "/var/postgresql"
+
+ # NOTE: this tasks needs `pipelining` set to `false` to work correctly
+- name: init postgres database
+ command:
+ cmd: 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"
+
+- name: enable and restart postgres service
+ service:
+ name: postgresql
+ state: restarted
+ enabled: true
remember that computers suck.