fix(database): more resilient postgres install

- Classified tasks with conditionals
- Added separate plays for installing/configuring
postgresql and for administrating the pleroma
database.
- Added a handler to restart postgres when its
configuration changes.
- Removed the task that automatically restarts postgres.
This was replaced by a task to enable the service only.

Part of dananglin/pleroma-ansible-playbook#17
This commit is contained in:
Dan Anglin 2020-06-30 00:27:13 +01:00
parent 20667709b2
commit 6219f78ffb
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 29 additions and 3 deletions

View file

@ -1,12 +1,12 @@
---
- name: Initialising the playbook.
- name: Gathering user's configuration.
hosts: all
roles:
- init
tags:
- always
- name: Setting up the Pleroma database.
- name: Installing and configuring the PostgreSQL engine.
hosts: pleroma_database
become: yes
become_method: sudo
@ -14,6 +14,19 @@
- pleroma-database
tags:
- pleroma-database
vars:
pleroma_database_installation: True
- name: Performing database administration.
hosts: pleroma_database
become: yes
become_method: sudo
roles:
- pleroma-database
tags:
- pleroma-database
vars:
pleroma_database_administration: True
- name: Setting up Pleroma.
hosts: pleroma_main

View file

@ -3,6 +3,7 @@
apk:
name: "{{ pleroma_postgres_packages }}"
state: present
when: pleroma_database_installation | default(False)
- name: Postgres -- Ensure that the database is initialised.
command:
@ -10,6 +11,7 @@
- /etc/init.d/postgresql
- setup
creates: /var/lib/postgresql/11/data/postgresql.conf
when: pleroma_database_installation | default(False)
- name: Postgres -- Ensuring that the additional directories exist.
file:
@ -21,6 +23,7 @@
loop:
- "{{ pleroma_postgres_log_dir }}"
- "{{ pleroma_postgres_confd }}"
when: pleroma_database_installation | default(False)
- name: Postgres -- Ensuring that PostgreSQL is configured.
template:
@ -32,6 +35,8 @@
loop:
- { src: etc_postgresql_pg_hba.conf.j2, dest: "{{ pleroma_postgres_base_conf }}/pg_hba.conf" }
- { src: etc_postgresql_confd_postgresql_override.conf, dest: "{{ pleroma_postgres_confd }}/postgresql_override.conf" }
when: pleroma_database_installation | default(False)
notify: "restart postgres"
- name: Postgres -- Ensuring that the symlink to the override config is present.
file:
@ -41,6 +46,8 @@
path: "{{ pleroma_postgres_confd_symlink }}"
src: "{{ pleroma_postgres_confd }}"
state: link
when: pleroma_database_installation | default(False)
notify: "restart postgres"
- name: Postgres -- Ensuring that the override config is included in the main config.
lineinfile:
@ -51,12 +58,14 @@
path: "{{ pleroma_postgres_base_conf }}/postgresql.conf"
regexp: ^.*include\s=\s'.*'.*$
state: present
when: pleroma_database_installation | default(False)
notify: "restart postgres"
- name: Postgres -- Ensuring that PostgreSQL is enabled and started.
service:
name: postgresql
enabled: yes
state: restarted
when: pleroma_database_installation | default(False)
- name: Postgres -- Ensuring that Postgres is available before continuing.
wait_for:
@ -65,6 +74,7 @@
host: localhost
port: 5432
state: started
when: pleroma_database_administration | default(False)
- name: Postgres -- Ensuring that the database user {{ pleroma.config.db.user }} exists.
become_user: postgres
@ -77,6 +87,7 @@
state: present
vars:
ansible_ssh_pipelining: true
when: pleroma_database_administration | default(False)
- name: Postgres -- Ensuring that the database {{ pleroma.config.db.name }} exists.
become_user: postgres
@ -89,6 +100,7 @@
state: present
vars:
ansible_ssh_pipelining: true
when: pleroma_database_administration | default(False)
- name: Postgres -- Ensuring the PostgreSQL extensions is added to the database.
become_user: postgres
@ -103,3 +115,4 @@
- uuid-ossp
vars:
ansible_ssh_pipelining: true
when: pleroma_database_administration | default(False)