aboutsummaryrefslogtreecommitdiffstats
path: root/roles/postgresql/tasks/main.yml
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2024-02-13 23:09:02 +0100
committerRomain Gonçalves <me@rgoncalves.se>2024-02-13 23:16:09 +0100
commit479efa19547bf710e0113b08bc6165b66d1b7980 (patch)
tree4f4bb17bdcca43ec7fd14ccf0b07dc316dc29541 /roles/postgresql/tasks/main.yml
parent075faa3ab59f2e5569cbd7c947251135e378e211 (diff)
downloadrules-479efa19547bf710e0113b08bc6165b66d1b7980.tar.gz
feat(roles/postgresql): simplify postgresql init
Diffstat (limited to 'roles/postgresql/tasks/main.yml')
-rw-r--r--roles/postgresql/tasks/main.yml39
1 files changed, 39 insertions, 0 deletions
diff --git a/roles/postgresql/tasks/main.yml b/roles/postgresql/tasks/main.yml
new file mode 100644
index 0000000..a59faa2
--- /dev/null
+++ b/roles/postgresql/tasks/main.yml
@@ -0,0 +1,39 @@
+---
+
+- name: install postgresql
+ ansible.builtin.package:
+ name:
+ - postgresql-server
+ - postgresql-contrib
+ state: present
+
+- name: install python libraries for ansible
+ ansible.builtin.package:
+ name: py3-psycopg2
+ state: present
+
+- name: create postgresql data directory
+ ansible.builtin.file:
+ path: "{{ postgresql__data_dir }}"
+ owner: "{{ postgresql__user }}"
+ group: "{{ postgresql__group }}"
+ mode: "0700"
+ state: directory
+
+- name: init postgresql database # noqa: no-changed-when
+ ansible.builtin.command:
+ argv:
+ - initdb
+ - "--pgdata={{ postgresql__data_dir }}"
+ - "--username={{ postgresql__db_user }}"
+ - --encoding=UTF-8
+ - --locale=en_US.UTF-8
+ creates: "{{ postgresql__data_dir }}/PG_VERSION"
+ become: true
+ become_user: "{{ postgresql__user }}"
+
+- name: enable and restart postgresql service
+ ansible.builtin.service:
+ name: postgresql
+ state: restarted
+ enabled: true
remember that computers suck.