This repository was archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgre-cluster.yml
More file actions
73 lines (62 loc) · 2.09 KB
/
postgre-cluster.yml
File metadata and controls
73 lines (62 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
- hosts: all
become: true
vars:
server_list:
- 192.168.3.234 #MASTER
- 192.168.3.233 #REPLICA
tasks:
- name: Install PostgreSQL
ansible.builtin.apt:
name:
- postgresql-12
update_cache: true
- name: Listen on all address
ansible.builtin.shell: |
pg_conftool set listen_addresses '*'
### RUN ON SERVER MASTER
- name: Set Postgresql.conf
ansible.builtin.shell: |
pg_conftool set wal_level replica
pg_conftool set synchronous_commit on
pg_conftool set max_wal_senders 10
pg_conftool set wal_keep_segments 10
pg_conftool set synchronous_standby_names '*'
delegate_to: "{{server_list[0]}}"
- name: Add Server list to pg_hba.conf for database replication
ansible.builtin.lineinfile:
path: /etc/postgresql/12/main/pg_hba.conf
regexp: 'host replication repuser {{item}}/32 trust'
line: 'host replication repuser {{item}}/32 trust'
loop:
"{{server_list}}"
delegate_to: "{{server_list[0]}}"
- name: Create user
ansible.builtin.shell: |
sudo -u postgres createuser --replication repuser
delegate_to: "{{server_list[0]}}"
- name: Restart and Enable PostgreSQL service
ansible.builtin.service:
name: postgresql
state: restarted
enabled: true
delegate_to: "{{server_list[0]}}"
###RUN ON SERVER REPLICA
- name: Stop Postgre server
ansible.builtin.service:
name: postgresql
state: stopped
delegate_to: "{{server_list[1]}}"
- name: run pg_basebackup
ansible.builtin.shell: |
pg_basebackup -R -h "{{server_list[0]}}" -U repuser -D /var/lib/postgresql/12/main -P -w
delegate_to: "{{server_list[1]}}"
- name: add hot_standby
ansible.builtin.shell: |
pg_conftool set hot_standby on
delegate_to: "{{server_list[1]}}"
- name: Start and Enable PostgreSQL service
ansible.builtin.service:
name: postgresql
state: started
enabled: true
delegate_to: "{{server_list[1]}}"