pvc-ansible/roles/pvc/tasks/patroni/main.yml

115 lines
2.5 KiB
YAML
Raw Normal View History

2023-09-01 15:42:19 -04:00
---
- set_fact:
package_list:
- python3-psycopg2
2023-09-01 15:42:19 -04:00
- python3-kazoo
- python-psycopg2
- python-kazoo
2023-09-01 15:42:19 -04:00
- patroni
- postgresql-11
2023-09-01 15:42:28 -04:00
postgresql_version: 11
2023-09-01 15:42:30 -04:00
when: debian_version|int == 10
2023-09-01 15:42:26 -04:00
- set_fact:
package_list:
- python3-psycopg2
- python3-kazoo
- patroni
2023-09-01 15:42:28 -04:00
- postgresql
2023-09-01 15:42:28 -04:00
postgresql_version: 13
2023-09-01 15:42:30 -04:00
when: debian_version|int == 11
- set_fact:
package_list:
- python3-psycopg2
- python3-kazoo
- patroni
- postgresql
postgresql_version: 15
when: debian_version|int == 12
2023-09-01 15:42:26 -04:00
- name: install patroni packages via apt
apt:
name: "{{ package_list }}"
2023-09-01 15:42:19 -04:00
state: latest
update-cache: yes
2023-09-01 15:42:30 -04:00
register: apt_res
retries: 5
until: apt_res is success
2023-09-01 15:42:19 -04:00
- name: stop and disable postgresql
service:
name: "{{ item }}"
state: stopped
enabled: no
with_items:
2023-09-01 15:42:28 -04:00
- "postgresql"
- "postgresql@{{ postgresql_version }}-main"
2023-09-01 15:42:19 -04:00
when: newhost is defined and newhost
- name: remove obsolete database directories
file:
dest: "{{ item }}"
state: absent
with_items:
2023-09-01 15:42:28 -04:00
- "/etc/postgresql/{{ postgresql_version }}"
- "/var/lib/postgresql/{{ postgresql_version }}"
2023-09-01 15:42:19 -04:00
when: newhost is defined and newhost
- name: create patroni database directory
file:
dest: /var/lib/postgresql/patroni/pvc
state: directory
owner: postgres
mode: 0700
when: newhost is defined and newhost
- name: install postgresql customization configuration file
template:
src: patroni/postgresql.pvc.conf.j2
dest: /etc/postgresql/postgresql.pvc.conf
owner: postgres
group: sudo
mode: 0640
notify: restart patroni
- name: install patroni configuration file
template:
src: patroni/patroni.yml.j2
dest: /etc/patroni/config.yml
owner: postgres
group: postgres
mode: 0640
notify: restart patroni
- name: install check_mk agent check
copy:
src: patroni/postgres
dest: /usr/lib/check_mk_agent/plugins/postgres
mode: 0755
- name: install initial schema files
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: postgres
group: sudo
mode: 0640
with_items:
- { src: "patroni/powerdns-schema.sql", dest: "/etc/postgresql/powerdns-schema.sql" }
- include: patroni/bootstrap.yml
run_once: yes
when: do_bootstrap is defined and do_bootstrap
2023-09-01 15:42:19 -04:00
- name: start but disable services (managed by PVC)
2023-09-01 15:42:19 -04:00
service:
name: "{{ item }}"
2023-09-01 15:42:19 -04:00
state: started
enabled: no
ignore_errors: yes
2023-09-01 15:42:19 -04:00
with_items:
- patroni
- meta: flush_handlers