115 lines
2.5 KiB
YAML
115 lines
2.5 KiB
YAML
---
|
|
- set_fact:
|
|
package_list:
|
|
- python3-psycopg2
|
|
- python3-kazoo
|
|
- python-psycopg2
|
|
- python-kazoo
|
|
- patroni
|
|
- postgresql-11
|
|
postgresql_version: 11
|
|
when: debian_version|int == 10
|
|
|
|
- set_fact:
|
|
package_list:
|
|
- python3-psycopg2
|
|
- python3-kazoo
|
|
- patroni
|
|
- postgresql
|
|
postgresql_version: 13
|
|
when: debian_version|int == 11
|
|
|
|
- set_fact:
|
|
package_list:
|
|
- python3-psycopg2
|
|
- python3-kazoo
|
|
- patroni
|
|
- postgresql
|
|
postgresql_version: 15
|
|
when: debian_version|int == 12
|
|
|
|
- name: install patroni packages via apt
|
|
apt:
|
|
name: "{{ package_list }}"
|
|
state: latest
|
|
update-cache: yes
|
|
register: apt_res
|
|
retries: 5
|
|
until: apt_res is success
|
|
|
|
- name: stop and disable postgresql
|
|
service:
|
|
name: "{{ item }}"
|
|
state: stopped
|
|
enabled: no
|
|
with_items:
|
|
- "postgresql"
|
|
- "postgresql@{{ postgresql_version }}-main"
|
|
when: newhost is defined and newhost
|
|
|
|
- name: remove obsolete database directories
|
|
file:
|
|
dest: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- "/etc/postgresql/{{ postgresql_version }}"
|
|
- "/var/lib/postgresql/{{ postgresql_version }}"
|
|
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
|
|
|
|
- name: start but disable services (managed by PVC)
|
|
service:
|
|
name: "{{ item }}"
|
|
state: started
|
|
enabled: no
|
|
ignore_errors: yes
|
|
with_items:
|
|
- patroni
|
|
|
|
- meta: flush_handlers
|