forked from vitabaks/autobase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_upgrade_rollback.yml
60 lines (56 loc) · 2.32 KB
/
pg_upgrade_rollback.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
---
# This playbook performs a rollback of a PostgreSQL upgrade.
# It's designed to be used when a PostgreSQL upgrade hasn't been fully completed and the new version hasn't been started.
# The rollback operation is performed by starting the Patroni cluster with the old version of PostgreSQL using the same PGDATA.
# The playbook first checks the health of the current cluster, verifies the version of PostgreSQL, and ensures the new PostgreSQL is not running.
# If these checks pass, the playbook switches back to the old PostgreSQL paths and restarts the Patroni service.
- name: "pg_upgrade_rollback.yml | Rollback the PostgreSQL upgrade"
hosts: postgres_cluster
gather_facts: true
any_errors_fatal: true
pre_tasks:
- name: "Set variable: ansible_python_interpreter"
ansible.builtin.set_fact:
ansible_python_interpreter: "/usr/bin/env python3"
when: "'python3' not in (ansible_python_interpreter | default(''))"
- name: Include main variables
ansible.builtin.include_vars: "vars/main.yml"
- name: Include upgrade variables
ansible.builtin.include_vars: "vars/upgrade.yml"
tasks:
- name: '[Prepare] Add host to group "primary" (in-memory inventory)'
ansible.builtin.add_host:
name: "{{ item }}"
groups: primary
# As Primary we specify the host in the 'master' group in the inventory file.
loop: "{{ groups['master'] }}"
changed_when: false
- name: '[Prepare] Add hosts to group "secondary" (in-memory inventory)'
ansible.builtin.add_host:
name: "{{ item }}"
groups: secondary
# As Secondary we specify the hosts in the 'replica' group in the inventory file.
loop: "{{ groups['replica'] }}"
changed_when: false
tags:
- always
- name: "Perform Rollback"
hosts: 'primary:secondary'
gather_facts: false
become: true
become_user: postgres
any_errors_fatal: true
pre_tasks:
- name: Include main variables
ansible.builtin.include_vars: "vars/main.yml"
- name: Include OS-specific variables
ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml"
- name: Include upgrade variables
ansible.builtin.include_vars: "vars/upgrade.yml"
tasks:
- name: Running rollback.yml
ansible.builtin.include_role:
name: upgrade
tasks_from: rollback
tags:
- rollback