File: main.yml

package info (click to toggle)
check-pgbackrest 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,396 kB
  • sloc: perl: 972; sh: 488; python: 145; makefile: 33
file content (84 lines) | stat: -rw-r--r-- 2,549 bytes parent folder | download
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
---
- name: Reference PG variables
  ansible.builtin.include_vars: "PG_{{ ansible_os_family }}.yml"

- name: Gather service facts
  ansible.builtin.service_facts:

- name: Firewall open Postgres TCP port {{ pg_port }}
  ansible.posix.firewalld:
    port: "{{ pg_port }}/tcp"
    permanent: true
    state: enabled
    immediate: true
  when:
    - ansible_facts.services['firewalld.service'] is defined
    - ansible_facts.services['firewalld.service'].state == 'running'
    - ansible_facts.services['firewalld.service'].status == 'enabled'
  become: true

- name: Gather the cluster_nodes information
  ansible.builtin.set_fact:
    pg_cluster_nodes: "{{ lookup('pg_sr_cluster_nodes', wantlist=True) }}"

- name: Get the primary information
  ansible.builtin.set_fact:
    primary_inventory_hostname: "{{ node.inventory_hostname }}"
  loop: "{{ pg_cluster_nodes }}"
  loop_control:
    loop_var: node
  when: node.node_type == 'primary'
  run_once: true

- name: Prepare hba list
  ansible.builtin.set_fact:
    pg_allow_ip_addresses: >-
      {{ pg_allow_ip_addresses | default([]) + [
        {
          "contype": "host",
          "users": pg_replication_user,
          "source": node.private_ip + "/32",
          "databases": "replication"
          },
          {
           "contype": "host",
           "users": pg_replication_user,
           "source": node.private_ip + "/32",
           "databases": "postgres"
           }
        ] }}
  loop: "{{ pg_cluster_nodes }}"
  loop_control:
    loop_var: node
  run_once: true

- name: Update primary for replication
  ansible.builtin.import_tasks: primary_settings.yml
  run_once: true
  delegate_to: "{{ primary_inventory_hostname }}"

- name: Call upstream update based on the upstream node
  ansible.builtin.import_tasks: upstream_node.yml
  when:
    - hostvars[inventory_hostname].upstream_node_private_ip is defined

- name: Build standby service check
  become: true
  block:
    - name: Create directories if not exists
      ansible.builtin.import_tasks: create_directories.yml
    - name: Take PG base backup
      ansible.builtin.import_tasks: pg_basebackup.yml
    - name: Setup systemd file
      ansible.builtin.import_tasks: pg_setup_systemd.yml
    - name: Configure standby node
      ansible.builtin.import_tasks: configure_node.yml

- name: Validate replication setup
  ansible.builtin.import_tasks: validate_setup_replication.yml

- name: Reset variables
  ansible.builtin.set_fact:
    primary_inventory_hostname: ""
    pg_allow_ip_addresses: []
  register: output