homelab/ansible/playbooks/database.yml

51 lines
1.6 KiB
YAML
Raw Normal View History

---
- hosts: database
vars:
# certbot_force: true
2024-05-08 19:14:37 +00:00
pre_tasks:
- name: Add database member to pg_hba replication
set_fact:
postgresql_hba_entries: "{{postgresql_hba_entries + [\
{'type':'host', \
'database': 'replication',\
'user':'repli',\
'address':hostvars[item]['ansible_'+default_interface]['ipv4']['address']+'/32',\
'auth_method':'trust'}] }}"
loop: "{{ groups.database }}"
roles:
- role: ansible-role-postgresql
become: true
2022-11-29 20:23:44 +00:00
tasks:
2022-10-23 15:31:08 +00:00
- name: add pg_read_all_data to dump
community.postgresql.postgresql_membership:
2022-11-29 20:23:44 +00:00
target_roles:
2022-10-23 15:31:08 +00:00
- dump
groups:
2022-11-29 20:23:44 +00:00
- pg_read_all_data
2022-10-23 15:31:08 +00:00
become: true
become_user: "{{ postgresql_user }}"
2024-05-08 19:14:37 +00:00
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
command: pg_basebackup -D /var/lib/postgres/data -h {{groups["database_active"]|first}} -U repli -Fp -Xs -P -R -w
become: true
become_user: postgres
when: inventory_hostname in groups["database_standby"] and not in_recovery.stat.exists
- name: Ensure PostgreSQL is started and enabled on boot.
service:
name: "{{ postgresql_daemon }}"
state: "{{ postgresql_service_state }}"
enabled: "{{ postgresql_service_enabled }}"
become: true
2024-05-08 19:37:27 +00:00
- name: Install pg_vector.rs
aur:
name: pgvecto.rs-bin
become: true
become_user: aur_builder