2023-09-01 15:42:19 -04:00
|
|
|
---
|
2023-09-01 15:42:26 -04:00
|
|
|
- set_fact:
|
|
|
|
package_list:
|
2023-09-01 15:42:26 -04:00
|
|
|
- python3-psycopg2
|
2023-09-01 15:42:19 -04:00
|
|
|
- python3-kazoo
|
2023-09-01 15:42:26 -04:00
|
|
|
- python-psycopg2
|
2023-09-01 15:42:26 -04:00
|
|
|
- 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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2023-12-10 00:24:19 -05:00
|
|
|
- name: install Prometheus postgresql exporter if enabled
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- prometheus-postgres-exporter
|
|
|
|
register: apt_res
|
|
|
|
retries: 5
|
|
|
|
until: apt_res is success
|
|
|
|
when: enable_prometheus_exporters is defined and enable_prometheus_exporters
|
|
|
|
|
2023-12-10 02:53:11 -05:00
|
|
|
- name: install Prometheus postgresql exporter config if enabled
|
|
|
|
template:
|
|
|
|
src: patroni/prometheus.env.j2
|
|
|
|
dest: /etc/default/prometheus-postgres-exporter
|
|
|
|
owner: prometheus
|
|
|
|
group: prometheus
|
|
|
|
mode: 0640
|
|
|
|
notify:
|
|
|
|
- restart prometheus-postgres
|
|
|
|
when: enable_prometheus_exporters is defined and enable_prometheus_exporters
|
|
|
|
|
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
|
2023-09-01 15:42:29 -04:00
|
|
|
when: do_bootstrap is defined and do_bootstrap
|
2023-09-01 15:42:19 -04:00
|
|
|
|
2023-09-01 15:42:25 -04:00
|
|
|
- name: start but disable services (managed by PVC)
|
2023-09-01 15:42:19 -04:00
|
|
|
service:
|
2023-09-01 15:42:25 -04:00
|
|
|
name: "{{ item }}"
|
2023-09-01 15:42:19 -04:00
|
|
|
state: started
|
2023-09-01 15:42:25 -04:00
|
|
|
enabled: no
|
2023-09-01 15:42:30 -04:00
|
|
|
ignore_errors: yes
|
2023-09-01 15:42:19 -04:00
|
|
|
with_items:
|
|
|
|
- patroni
|
|
|
|
|
|
|
|
- meta: flush_handlers
|