2023-09-01 15:42:19 -04:00
|
|
|
---
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: stop patroni services
|
|
|
|
service:
|
|
|
|
name: "{{ item }}.service"
|
|
|
|
state: stopped
|
|
|
|
enabled: no
|
|
|
|
with_items:
|
|
|
|
- patroni
|
|
|
|
|
|
|
|
- name: remove any existing patroni keys in Zookeeper
|
2023-09-01 15:42:28 -04:00
|
|
|
shell: "/usr/share/zookeeper/bin/zkCli.sh -server $(hostname -s):2181 rmr /patroni"
|
2023-09-01 15:42:22 -04:00
|
|
|
ignore_errors: true
|
|
|
|
|
2023-09-01 15:42:25 -04:00
|
|
|
- name: start Patroni
|
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
|
|
|
|
with_items:
|
|
|
|
- patroni
|
|
|
|
|
|
|
|
- name: wait 15s for cluster to initialize
|
|
|
|
pause:
|
|
|
|
seconds: 15
|
|
|
|
|
2023-09-01 15:42:25 -04:00
|
|
|
- name: test connecting to cluster
|
2023-09-01 15:42:28 -04:00
|
|
|
shell: "sudo -u postgres psql postgres -c 'select * from pg_stat_activity' || ( systemctl restart patroni && exit 1 )"
|
2023-09-01 15:42:25 -04:00
|
|
|
register: result
|
2023-09-01 15:42:28 -04:00
|
|
|
retries: 8
|
|
|
|
delay: 15
|
2023-09-01 15:42:25 -04:00
|
|
|
until: result.rc == 0
|
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- block:
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: create user for DNS role
|
2023-09-01 15:42:19 -04:00
|
|
|
postgresql_user:
|
|
|
|
name: "{{ pvc_dns_database_user }}"
|
|
|
|
password: "{{ pvc_dns_database_password }}"
|
|
|
|
encrypted: yes
|
|
|
|
state: present
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: create database for DNS role
|
2023-09-01 15:42:19 -04:00
|
|
|
postgresql_db:
|
|
|
|
name: "{{ pvc_dns_database_name }}"
|
|
|
|
owner: "{{ pvc_dns_database_user }}"
|
|
|
|
encoding: utf8
|
|
|
|
state: present
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: set user privs for DNS role
|
2023-09-01 15:42:19 -04:00
|
|
|
postgresql_user:
|
|
|
|
name: "{{ pvc_dns_database_user }}"
|
|
|
|
db: "{{ pvc_dns_database_name }}"
|
|
|
|
priv: ALL
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: create user for Provisioner role
|
|
|
|
postgresql_user:
|
2023-09-01 15:42:24 -04:00
|
|
|
name: "{{ pvc_api_database_user }}"
|
|
|
|
password: "{{ pvc_api_database_password }}"
|
2023-09-01 15:42:22 -04:00
|
|
|
encrypted: yes
|
|
|
|
state: present
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
|
|
|
- name: create database for Provisioner role
|
|
|
|
postgresql_db:
|
2023-09-01 15:42:24 -04:00
|
|
|
name: "{{ pvc_api_database_name }}"
|
|
|
|
owner: "{{ pvc_api_database_user }}"
|
2023-09-01 15:42:22 -04:00
|
|
|
encoding: utf8
|
|
|
|
state: present
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
|
|
|
- name: set user privs for Provisioner role
|
|
|
|
postgresql_user:
|
2023-09-01 15:42:24 -04:00
|
|
|
name: "{{ pvc_api_database_user }}"
|
|
|
|
db: "{{ pvc_api_database_name }}"
|
2023-09-01 15:42:22 -04:00
|
|
|
priv: ALL
|
|
|
|
login_host: /run/postgresql
|
|
|
|
|
|
|
|
- name: create extensions for DNS database
|
2023-09-01 15:42:19 -04:00
|
|
|
postgresql_ext:
|
|
|
|
name: "{{ item }}"
|
|
|
|
db: "{{ pvc_dns_database_name }}"
|
|
|
|
login_host: /run/postgresql
|
|
|
|
with_items: "{{ extensions }}"
|
|
|
|
when: extensions is defined
|
|
|
|
|
2023-09-01 15:42:22 -04:00
|
|
|
- name: create extensions for Provisioner database
|
|
|
|
postgresql_ext:
|
|
|
|
name: "{{ item }}"
|
2023-09-01 15:42:24 -04:00
|
|
|
db: "{{ pvc_api_database_name }}"
|
2023-09-01 15:42:22 -04:00
|
|
|
login_host: /run/postgresql
|
|
|
|
with_items: "{{ extensions }}"
|
|
|
|
when: extensions is defined
|
|
|
|
|
|
|
|
- name: import DNS database schema
|
2023-09-01 15:42:19 -04:00
|
|
|
command: "psql -U {{ pvc_dns_database_user }} -f /etc/postgresql/powerdns-schema.sql {{ pvc_dns_database_name }}"
|
|
|
|
|
|
|
|
become: yes
|
|
|
|
become_user: postgres
|