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:
parent
20667709b2
commit
6219f78ffb
2 changed files with 29 additions and 3 deletions
17
playbook.yml
17
playbook.yml
|
@ -1,12 +1,12 @@
|
||||||
---
|
---
|
||||||
- name: Initialising the playbook.
|
- name: Gathering user's configuration.
|
||||||
hosts: all
|
hosts: all
|
||||||
roles:
|
roles:
|
||||||
- init
|
- init
|
||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
- name: Setting up the Pleroma database.
|
- name: Installing and configuring the PostgreSQL engine.
|
||||||
hosts: pleroma_database
|
hosts: pleroma_database
|
||||||
become: yes
|
become: yes
|
||||||
become_method: sudo
|
become_method: sudo
|
||||||
|
@ -14,6 +14,19 @@
|
||||||
- pleroma-database
|
- pleroma-database
|
||||||
tags:
|
tags:
|
||||||
- pleroma-database
|
- 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.
|
- name: Setting up Pleroma.
|
||||||
hosts: pleroma_main
|
hosts: pleroma_main
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
apk:
|
apk:
|
||||||
name: "{{ pleroma_postgres_packages }}"
|
name: "{{ pleroma_postgres_packages }}"
|
||||||
state: present
|
state: present
|
||||||
|
when: pleroma_database_installation | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensure that the database is initialised.
|
- name: Postgres -- Ensure that the database is initialised.
|
||||||
command:
|
command:
|
||||||
|
@ -10,6 +11,7 @@
|
||||||
- /etc/init.d/postgresql
|
- /etc/init.d/postgresql
|
||||||
- setup
|
- setup
|
||||||
creates: /var/lib/postgresql/11/data/postgresql.conf
|
creates: /var/lib/postgresql/11/data/postgresql.conf
|
||||||
|
when: pleroma_database_installation | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that the additional directories exist.
|
- name: Postgres -- Ensuring that the additional directories exist.
|
||||||
file:
|
file:
|
||||||
|
@ -21,6 +23,7 @@
|
||||||
loop:
|
loop:
|
||||||
- "{{ pleroma_postgres_log_dir }}"
|
- "{{ pleroma_postgres_log_dir }}"
|
||||||
- "{{ pleroma_postgres_confd }}"
|
- "{{ pleroma_postgres_confd }}"
|
||||||
|
when: pleroma_database_installation | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that PostgreSQL is configured.
|
- name: Postgres -- Ensuring that PostgreSQL is configured.
|
||||||
template:
|
template:
|
||||||
|
@ -32,6 +35,8 @@
|
||||||
loop:
|
loop:
|
||||||
- { src: etc_postgresql_pg_hba.conf.j2, dest: "{{ pleroma_postgres_base_conf }}/pg_hba.conf" }
|
- { 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" }
|
- { 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.
|
- name: Postgres -- Ensuring that the symlink to the override config is present.
|
||||||
file:
|
file:
|
||||||
|
@ -41,6 +46,8 @@
|
||||||
path: "{{ pleroma_postgres_confd_symlink }}"
|
path: "{{ pleroma_postgres_confd_symlink }}"
|
||||||
src: "{{ pleroma_postgres_confd }}"
|
src: "{{ pleroma_postgres_confd }}"
|
||||||
state: link
|
state: link
|
||||||
|
when: pleroma_database_installation | default(False)
|
||||||
|
notify: "restart postgres"
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that the override config is included in the main config.
|
- name: Postgres -- Ensuring that the override config is included in the main config.
|
||||||
lineinfile:
|
lineinfile:
|
||||||
|
@ -51,12 +58,14 @@
|
||||||
path: "{{ pleroma_postgres_base_conf }}/postgresql.conf"
|
path: "{{ pleroma_postgres_base_conf }}/postgresql.conf"
|
||||||
regexp: ^.*include\s=\s'.*'.*$
|
regexp: ^.*include\s=\s'.*'.*$
|
||||||
state: present
|
state: present
|
||||||
|
when: pleroma_database_installation | default(False)
|
||||||
|
notify: "restart postgres"
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that PostgreSQL is enabled and started.
|
- name: Postgres -- Ensuring that PostgreSQL is enabled and started.
|
||||||
service:
|
service:
|
||||||
name: postgresql
|
name: postgresql
|
||||||
enabled: yes
|
enabled: yes
|
||||||
state: restarted
|
when: pleroma_database_installation | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that Postgres is available before continuing.
|
- name: Postgres -- Ensuring that Postgres is available before continuing.
|
||||||
wait_for:
|
wait_for:
|
||||||
|
@ -65,6 +74,7 @@
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 5432
|
port: 5432
|
||||||
state: started
|
state: started
|
||||||
|
when: pleroma_database_administration | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that the database user {{ pleroma.config.db.user }} exists.
|
- name: Postgres -- Ensuring that the database user {{ pleroma.config.db.user }} exists.
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
|
@ -77,6 +87,7 @@
|
||||||
state: present
|
state: present
|
||||||
vars:
|
vars:
|
||||||
ansible_ssh_pipelining: true
|
ansible_ssh_pipelining: true
|
||||||
|
when: pleroma_database_administration | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring that the database {{ pleroma.config.db.name }} exists.
|
- name: Postgres -- Ensuring that the database {{ pleroma.config.db.name }} exists.
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
|
@ -89,6 +100,7 @@
|
||||||
state: present
|
state: present
|
||||||
vars:
|
vars:
|
||||||
ansible_ssh_pipelining: true
|
ansible_ssh_pipelining: true
|
||||||
|
when: pleroma_database_administration | default(False)
|
||||||
|
|
||||||
- name: Postgres -- Ensuring the PostgreSQL extensions is added to the database.
|
- name: Postgres -- Ensuring the PostgreSQL extensions is added to the database.
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
|
@ -103,3 +115,4 @@
|
||||||
- uuid-ossp
|
- uuid-ossp
|
||||||
vars:
|
vars:
|
||||||
ansible_ssh_pipelining: true
|
ansible_ssh_pipelining: true
|
||||||
|
when: pleroma_database_administration | default(False)
|
||||||
|
|
Reference in a new issue