feat: improve database playbook

This commit is contained in:
vincent 2024-05-10 08:23:54 +02:00
parent 7244ceb5b1
commit 74794f866a

View File

@ -1,45 +1,34 @@
--- ---
- hosts: database - name: Database playbook
hosts: database
vars: vars:
# certbot_force: true # certbot_force: true
pre_tasks: pre_tasks:
- name: Add database member to pg_hba replication - name: Add database member to pg_hba replication
set_fact: ansible.builtin.set_fact:
postgresql_hba_entries: "{{ postgresql_hba_entries + [\ postgresql_hba_entries: "{{ postgresql_hba_entries + [\
{'type':'host', \ {'type':'host', \
'database': 'replication',\ 'database': 'replication',\
'user':'repli',\ 'user':'repli',\
'address':hostvars[item]['ansible_'+default_interface]['ipv4']['address']+'/32',\ 'address':hostvars[item]['ansible_'+default_interface]['ipv4']['address']+'/32',\
'auth_method':'trust'}] }}" 'auth_method':'trust'}] }}"
loop: "{{ groups.database }}" loop: '{{ groups.database }}'
roles: roles:
- role: ansible-role-postgresql - role: ansible-role-postgresql
become: true become: true
tasks: tasks:
- name: add pg_read_all_data to dump
community.postgresql.postgresql_membership:
target_roles:
- dump
groups:
- pg_read_all_data
become: true
become_user: "{{ postgresql_user }}"
when: inventory_hostname in groups["database_active"]
- name: Check if inactive database is initialised
ansible.builtin.stat:
path: /var/lib/postgres/data/postgresql.conf
become: true
register: in_recovery
- name: Launch replication - name: Launch replication
command: pg_basebackup -D /var/lib/postgres/data -h {{groups["database_active"]|first}} -U repli -Fp -Xs -P -R -w ansible.builtin.command: pg_basebackup -D /var/lib/postgres/data -h {{groups["database_active"]|first}} -U repli -Fp -Xs -P -R -w
args:
creates: /var/lib/postgres/data/postgresql.conf
become: true become: true
become_user: postgres become_user: postgres
when: inventory_hostname in groups["database_standby"] and not in_recovery.stat.exists when: inventory_hostname in groups["database_standby"]
- name: Ensure PostgreSQL is started and enabled on boot. - name: Ensure PostgreSQL is started and enabled on boot.
service: ansible.builtin.service:
name: "{{ postgresql_daemon }}" name: '{{ postgresql_daemon }}'
state: "{{ postgresql_service_state }}" state: '{{ postgresql_service_state }}'
enabled: "{{ postgresql_service_enabled }}" enabled: '{{ postgresql_service_enabled }}'
become: true become: true
- name: Install pg_vector.rs - name: Install pg_vector.rs
aur: aur: