homelab/ansible/playbooks/database.yml

55 lines
1.8 KiB
YAML
Raw Normal View History

---
2024-05-10 06:23:54 +00:00
- name: Database playbook
hosts: database
vars:
# certbot_force: true
2024-05-08 19:14:37 +00:00
pre_tasks:
2024-06-29 08:20:25 +00:00
- name: Install Pg vertors (immich)
2024-08-04 09:49:40 +00:00
aur:
2024-06-29 08:20:25 +00:00
name: pgvecto.rs-bin
state: present
become: true
become_user: aur_builder
2024-05-08 19:14:37 +00:00
- name: Add database member to pg_hba replication
2024-05-10 06:23:54 +00:00
ansible.builtin.set_fact:
postgresql_hba_entries: "{{ postgresql_hba_entries + [\
2024-05-08 19:14:37 +00:00
{'type':'host', \
'database': 'replication',\
'user':'repli',\
2024-06-29 08:20:25 +00:00
'address':hostvars[item]['ansible_'+hostvars[item]['default_interface']]['ipv4']['address']+'/32',\
2024-05-08 19:14:37 +00:00
'auth_method':'trust'}] }}"
2024-05-10 06:23:54 +00:00
loop: '{{ groups.database }}'
roles:
- role: ansible-role-postgresql
become: true
2022-11-29 20:23:44 +00:00
tasks:
2024-05-08 19:14:37 +00:00
- name: Launch replication
2024-05-10 06:23:54 +00:00
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
2024-05-08 19:14:37 +00:00
become: true
become_user: postgres
2024-08-04 09:49:40 +00:00
when: inventory_hostname in groups["database_standby"]
2024-05-08 19:14:37 +00:00
- name: Ensure PostgreSQL is started and enabled on boot.
2024-05-10 06:23:54 +00:00
ansible.builtin.service:
name: '{{ postgresql_daemon }}'
state: '{{ postgresql_service_state }}'
enabled: '{{ postgresql_service_enabled }}'
2024-05-08 19:14:37 +00:00
become: true
2024-06-29 08:20:25 +00:00
2024-05-09 07:25:23 +00:00
- name: Set Postgress shared libraries
community.postgresql.postgresql_set:
name: shared_preload_libraries
value: vectors.so
become: true
become_user: postgres
when: inventory_hostname in groups["database_active"]
notify: Restart postgresql
- name: Set Postgress shared libraries
community.postgresql.postgresql_set:
name: search_path
value: '$user, public, vectors'
become: true
become_user: postgres
when: inventory_hostname in groups["database_active"]