-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_replica.yml
76 lines (67 loc) · 1.98 KB
/
deploy_replica.yml
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
74
75
76
---
- hosts: "{{ cluster_name }}"
remote_user: "{{ rmt_user }}"
become: yes
any_errors_fatal: yes
gather_facts: no
pre_tasks:
- name: "getting postgres replication info"
postgresql_info:
filter: replications
register: pg_info
when: inventory_hostname == primary_host
become_user: "{{ pg_os_user }}"
- name: setting parameter as the list of the replicated hosts
set_fact:
replicated_hosts: "{{ hostvars[primary_host].pg_info.replications.values() \
| map(attribute='client_hostname') \
| list }}"
- name: "Make sure standby is down before the sync"
systemd:
name: "{{ pg_srv_name }}"
state: stopped
when:
- inventory_hostname != primary_host
- inventory_hostname not in replicated_hosts
tags:
- rmt-pg-bck
- resync-standby
tasks:
- name: "Create replication user"
postgresql_user:
db: "{{ pg_db }}"
name: "{{ rep_user_name }}"
password: "{{ rep_user_pass }}"
role_attr_flags: "REPLICATION"
no_log: yes
become_user: "{{ pg_os_user }}"
environment:
PGDATA: "{{ pg_data }}"
when: inventory_hostname == primary_host
tags: rep-user
- import_role:
name: rmt-pg-bck
vars:
backup_dir: "{{ pg_data }}"
remote_host: "{{ primary_host }}"
when:
- inventory_hostname != primary_host
- inventory_hostname not in replicated_hosts
tags:
- rmt-pg-bck
- resync-standby
- import_role:
role: cfg-replica
tags:
- cfg-replica
- resync-standby
post_tasks:
- name: "Make sure the new standby is started after the configurarion change"
systemd:
name: "{{ pg_srv_name }}"
state: started
when:
- inventory_hostname != primary_host
- inventory_hostname not in replicated_hosts
tags: resync-standby
...