-
Notifications
You must be signed in to change notification settings - Fork 38
/
tower-pgsql-promote.yml
57 lines (47 loc) · 1.74 KB
/
tower-pgsql-promote.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
---
- name: Promote secondary HA/DR database to primary
hosts: database
vars_files: tower-vars.yml
become: true
tasks:
- name: import postgres role vars
import_role:
name: "{{tower_installer_current}}/roles/postgres"
vars:
postgres_exec_vars_only: true
- name: determine path for pg_ctl command
set_fact:
pg_conf_bin_inferred: "{{ pg_initdb_command | dirname }}"
- name: if Tower postgres role does not provide an SCL prefix
set_fact:
pg_bash: ""
when: pg_bash is not defined
- name: get the current postgres version
import_role:
name: samdoran.pgsql-replication
tasks_from: pgsql_version.yml
vars:
pgsqlrep_bash: "{{ pg_bash }}"
- name: Check recovery.conf
stat:
path: "{{ pg_conf_dir }}/recovery.conf"
register: recovery_conf
- name: Exit if secondary is already promoted or not in standby mode
fail:
msg: Secondary database server is not in standby mode.
when: recovery_conf.stat.isreg is not defined
ignore_errors: yes
- name: Promote secondary PostgreSQL server to primary
command: "{{ pg_conf_bin_inferred }}/pg_ctl promote -D {{ pg_conf_dir }}"
become_user: postgres
ignore_errors: yes
when: recovery_conf.stat.isreg is defined
- name: ensure replica is not in recovery mode
command: '{{ pg_bash }} psql -U postgres -t -c "select pg_is_in_recovery();"'
register: recovery_mode
changed_when: false
become_user: postgres
- name: check that recovery mode is off
debug:
msg: "Recovery mode is {{ recovery_mode.stdout.strip() == 'f' | ternary('FALSE', 'TRUE') }}"
failed_when: recovery_mode.stdout.strip() != 'f'