Skip to content

Commit

Permalink
Fix (Upgrade): Delegate maintenance mode tasks to 'balancers' group (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Jul 16, 2024
1 parent 3532496 commit 3b24f6e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Gather facts for hosts postres_cluster
- name: Gather facts from postgres_cluster hosts
ansible.builtin.setup:
delegate_to: "{{ item }}"
delegate_facts: true
Expand Down
10 changes: 10 additions & 0 deletions roles/upgrade/tasks/maintenance_disable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@
dest: /etc/haproxy/haproxy.cfg
owner: haproxy
group: haproxy
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true

- name: Reload haproxy service
ansible.builtin.systemd:
name: haproxy
state: reloaded
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true

- name: Start confd service
ansible.builtin.service:
name: confd
state: started
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true
become: true
become_user: root
ignore_errors: true # show the error and continue the playbook execution
when:
- groups.balancers | default([]) | length > 0
- with_haproxy_load_balancing | bool
- pgbouncer_install | bool
- pgbouncer_pool_pause | bool
Expand Down
17 changes: 17 additions & 0 deletions roles/upgrade/tasks/maintenance_enable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@
# Temporarily disable http-checks in order to keep database connections after stopping the Patroni service
# and then pause the pgbouncer pools.
- block:
- name: Gather facts from balancers
ansible.builtin.setup:
delegate_to: "{{ item }}"
delegate_facts: true
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true

- name: Stop confd service
ansible.builtin.service:
name: confd
state: stopped
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true
when: dcs_type == "etcd"

- name: Update haproxy conf file (disable http-checks)
Expand All @@ -28,14 +38,21 @@
dest: /etc/haproxy/haproxy.cfg
owner: haproxy
group: haproxy
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true

- name: Reload haproxy service
ansible.builtin.systemd:
name: haproxy
state: reloaded
delegate_to: "{{ item }}"
loop: "{{ groups.balancers | default([]) | list }}"
run_once: true
become: true
become_user: root
when:
- groups.balancers | default([]) | length > 0
- with_haproxy_load_balancing | bool
- pgbouncer_install | bool
- pgbouncer_pool_pause | bool
Expand Down
6 changes: 6 additions & 0 deletions roles/upgrade/tasks/update_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
dest: "{{ patroni_config_file }}.bkp"
remote_src: true

# https://github.com/vitabaks/postgresql_cluster/issues/666
- name: Remove patroni.dynamic.json file
ansible.builtin.file:
path: "{{ pg_old_datadir }}/patroni.dynamic.json"
state: absent

# Update the directory path to a new version of PostgresSQL
- name: "Edit patroni.yml | update parameters: data_dir, bin_dir, config_dir"
ansible.builtin.replace:
Expand Down

0 comments on commit 3b24f6e

Please sign in to comment.