forked from redhat-cop/automate-tower-ha-dr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tower-check-replication.yml
71 lines (59 loc) · 2.24 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
---
- hosts: database_replica
gather_facts: no
become: true
become_user: postgres
vars:
replication_time_threshold: 20
vars_files: tower-vars.yml
tasks:
- name: HIGH LEVEL BLOCK TO DETERMINE IF DB REPLICATION IS MANAGED BY TOOLKIT
block:
- name: check replication status and latency
#FROM ED pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
command: 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: 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() }}'"
failed_when: recovery_mode.stdout.strip() != 't'
when: not tower_db_external
- hosts: database
gather_facts: no
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:
- name: ensure master is not in recovery mode
command: 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() }}'"
failed_when: recovery_mode.stdout.strip() != 'f'
ignore_errors: yes
- name: ensure master db is configured on tower nodes
command: python -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