-
Notifications
You must be signed in to change notification settings - Fork 38
/
tower-check-replication.yml
93 lines (76 loc) · 2.8 KB
/
tower-check-replication.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
- hosts: database_replica
gather_facts: yes
become: true
become_user: postgres
vars:
replication_time_threshold: 100
vars_files: tower-vars.yml
tasks:
- name: high level block to determine if db replication is managed by toolkit
block:
# get tower postgres role vars
- name: import postgres role vars
import_role:
name: "{{tower_installer_current}}/roles/postgres"
vars:
postgres_exec_vars_only: true
- set_fact:
pg_bash: ""
when: pg_bash is not defined
- name: check replication status and latency
command: '{{ pg_bash }} psql -U postgres -t -c "select extract(epoch from now() - pg_last_xact_replay_timestamp());"'
register: replication_latency
changed_when: false
- name: extract datetime
debug:
msg: "Replication latency is {{ replication_latency.stdout | float }}"
failed_when: replication_latency.stdout | float > replication_time_threshold
- name: ensure replica is in recovery mode
command: '{{ pg_bash }} psql -U postgres -t -c "select pg_is_in_recovery();"'
register: recovery_mode
changed_when: false
- name: check recovery mode is set to true on replica(s)
debug:
msg: "Recovery mode is {{ (recovery_mode.stdout.strip() == 't') | ternary('TRUE', 'FALSE') }}"
failed_when: recovery_mode.stdout.strip() != 't'
when: not tower_db_external
- hosts: database
gather_facts: yes
become: true
become_user: postgres
vars_files: tower-vars.yml
tasks:
- name: high level block to determine if db replication is managed by toolkit
block:
# get tower postgres role vars
- name: import postgres role vars
import_role:
name: "{{tower_installer_current}}/roles/postgres"
vars:
postgres_exec_vars_only: true
- set_fact:
pg_bash: ""
when: pg_bash is not defined
- name: ensure master is not in recovery mode
command: '{{ pg_bash }} psql -U postgres -t -c "select pg_is_in_recovery();"'
register: recovery_mode
changed_when: false
- name: check recovery mode is set to false on primary
debug:
msg: "Recovery mode is {{ (recovery_mode.stdout.strip() == 't') | ternary('TRUE', 'FALSE') }}"
failed_when: recovery_mode.stdout.strip() != 'f'
ignore_errors: yes
- name: get master db configured on tower nodes
command: python2 -c "import postgres; print postgres.DATABASES['default']['HOST']"
args:
chdir: /etc/tower/conf.d
register: master_db
delegate_to: "{{ groups['tower'][0] }}"
become_user: root
changed_when: false
- name: check configured db for tower nodes
debug:
msg: "Configured db is {{ master_db.stdout }}"
failed_when: pg_host != master_db.stdout
when: not tower_db_external