aboutsummaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/postgres/defaults/main.yml7
-rw-r--r--roles/postgres/tasks/main.yml53
-rw-r--r--roles/postgresql/defaults/main.yml8
-rw-r--r--roles/postgresql/tasks/create_db.yml (renamed from roles/postgres/tasks/create_db.yml)0
-rw-r--r--roles/postgresql/tasks/create_user.yml (renamed from roles/postgres/tasks/create_user.yml)0
-rw-r--r--roles/postgresql/tasks/main.yml39
6 files changed, 47 insertions, 60 deletions
diff --git a/roles/postgres/defaults/main.yml b/roles/postgres/defaults/main.yml
deleted file mode 100644
index 856ac50..0000000
--- a/roles/postgres/defaults/main.yml
+++ /dev/null
@@ -1,7 +0,0 @@
----
-
-postgres_dir: /data/postgresql
-postgres_default_dir: /var/postgresql
-postgres_user: _postgresql
-postgres_group: _postgresql
-postgres_db_user: postgres
diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml
deleted file mode 100644
index f3d24da..0000000
--- a/roles/postgres/tasks/main.yml
+++ /dev/null
@@ -1,53 +0,0 @@
----
-
-- name: install postgres
- ansible.builtin.package:
- name:
- - postgresql-server
- - postgresql-contrib
- state: present
-
-- name: create postgres directories
- ansible.builtin.file:
- path: "{{ postgres_dir }}/{{ item }}"
- owner: "{{ postgres_user }}"
- group: "{{ postgres_group }}"
- mode: "0750"
- state: directory
- loop:
- - ""
- - "data"
-
-- name: delete default data dir if exists
- ansible.builtin.file:
- path: "{{ postgres_default_dir }}"
- state: absent
- when: postgres_dir != "/var/postgresql"
-
-- name: link postgres directory to default one
- ansible.builtin.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"
-
-- name: init postgres database # noqa: no-changed-when
- ansible.builtin.shell:
- cmd: |
- su "{{ postgres_user }}" \
- -c 'initdb -D "{{ postgres_dir }}/data/" -U "{{ postgres_db_user }}" --encoding=UTF-8 --locale=en_US.UTF-8'
- chdir: "{{ postgres_dir }}"
- register: result
- failed_when:
- - result.rc != 0
- - "'exists but is not empty' not in result.stderr"
-
-- name: enable and restart postgres service
- ansible.builtin.service:
- name: postgresql
- state: restarted
- enabled: true
diff --git a/roles/postgresql/defaults/main.yml b/roles/postgresql/defaults/main.yml
new file mode 100644
index 0000000..65f47df
--- /dev/null
+++ b/roles/postgresql/defaults/main.yml
@@ -0,0 +1,8 @@
+---
+
+postgresql__dir: /var/postgresql
+postgresql__data_dir: "{{ postgresql__dir }}/data"
+postgresql__user: _postgresql
+postgresql__group: _postgresql
+postgresql__db_user: postgres
+postgresql__port: 5432
diff --git a/roles/postgres/tasks/create_db.yml b/roles/postgresql/tasks/create_db.yml
index d2f3676..d2f3676 100644
--- a/roles/postgres/tasks/create_db.yml
+++ b/roles/postgresql/tasks/create_db.yml
diff --git a/roles/postgres/tasks/create_user.yml b/roles/postgresql/tasks/create_user.yml
index 793676e..793676e 100644
--- a/roles/postgres/tasks/create_user.yml
+++ b/roles/postgresql/tasks/create_user.yml
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.