Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions automation/roles/cloud_resources/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ database_public_allowed_ips: "" # (comma-separated list of IP addresses in CIDR

# Load balancer
cloud_load_balancer: true # Create a Load Balancer in the Cloud.
cloud_load_balancer_unified: false # Creates a single load balancer with different ports
cloud_load_balancer_replica_port: 5433
cloud_load_balancer_sync_port: 5434
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use the same ports as we do when using haproxy?

  master: 5000
  replicas: 5001
  replicas_sync: 5002
  replicas_async: 5003


# Backups (if 'pgbackrest_install' or 'wal_g_install' is 'true')
aws_s3_bucket_create: true # if 'cloud_provider=aws'
Expand Down
124 changes: 102 additions & 22 deletions automation/roles/cloud_resources/tasks/hetzner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,14 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
when: cloud_load_balancer | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Configure Load Balancer service"
hetzner.hcloud.load_balancer_service:
Expand Down Expand Up @@ -566,11 +568,77 @@
label: "{{ patroni_cluster_name }}-{{ item }}"
vars:
database_port: "{{ pgbouncer_listen_port | default(6432) if pgbouncer_install | bool else postgresql_port | default(5432) }}"
when: cloud_load_balancer | bool and
when: cloud_load_balancer | bool and not cloud_load_balancer_unified | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))

- name: "Hetzner Cloud: Configure Load Balancer primary service"
hetzner.hcloud.load_balancer_service:
api_token: "{{ lookup('ansible.builtin.env', 'HCLOUD_API_TOKEN') }}"
load_balancer: "{{ patroni_cluster_name }}-lb"
listen_port: "{{ hetzner_load_balancer_port | default(database_port) }}"
destination_port: "{{ pgbouncer_listen_port | default(6432) if pgbouncer_install | bool else postgresql_port | default(5432) }}"
protocol: tcp
health_check:
protocol: http
port: "{{ patroni_restapi_port }}"
interval: 5
timeout: 2
retries: 3
http:
path: "/primary"
status_codes:
- "200"
state: present
vars:
database_port: "{{ pgbouncer_listen_port | default(6432) if pgbouncer_install | bool else postgresql_port | default(5432) }}"
when: cloud_load_balancer | bool and cloud_load_balancer_unified | bool

- name: "Hetzner Cloud: Configure Load Balancer replica service"
hetzner.hcloud.load_balancer_service:
api_token: "{{ lookup('ansible.builtin.env', 'HCLOUD_API_TOKEN') }}"
load_balancer: "{{ patroni_cluster_name }}-lb"
listen_port: "{{ hetzner_load_balancer_replica_port | default(database_port) }}"
destination_port: "{{ pgbouncer_listen_port | default(6432) if pgbouncer_install | bool else postgresql_port | default(5432) }}"
protocol: tcp
health_check:
protocol: http
port: "{{ patroni_restapi_port }}"
interval: 5
timeout: 2
retries: 3
http:
path: "/replica"
status_codes:
- "200"
state: present
vars:
database_port: "{{ cloud_load_balancer_replica_port | default(5433) }}"
when: cloud_load_balancer | bool and cloud_load_balancer_unified | bool and server_count | int > 1

- name: "Hetzner Cloud: Configure Load Balancer sync service"
hetzner.hcloud.load_balancer_service:
api_token: "{{ lookup('ansible.builtin.env', 'HCLOUD_API_TOKEN') }}"
load_balancer: "{{ patroni_cluster_name }}-lb"
listen_port: "{{ hetzner_load_balancer_sync_port | default(database_port) }}"
destination_port: "{{ pgbouncer_listen_port | default(6432) if pgbouncer_install | bool else postgresql_port | default(5432) }}"
protocol: tcp
health_check:
protocol: http
port: "{{ patroni_restapi_port }}"
interval: 5
timeout: 2
retries: 3
http:
path: "/sync"
status_codes:
- "200"
state: present
vars:
database_port: "{{ cloud_load_balancer_sync_port | default(5434) }}"
when: cloud_load_balancer | bool and cloud_load_balancer_unified | bool and server_count | int > 1 and synchronous_mode | bool

- name: "Hetzner Cloud: Add Load Balancer to network '{{ server_network }}'"
hetzner.hcloud.load_balancer_network:
api_token: "{{ lookup('ansible.builtin.env', 'HCLOUD_API_TOKEN') }}"
Expand All @@ -581,12 +649,14 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
when: cloud_load_balancer | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Disable public interface for Load Balancer"
hetzner.hcloud.load_balancer:
Expand All @@ -598,16 +668,18 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
register: hetzner_load_balancer_disable_public
until: hetzner_load_balancer_disable_public is success
delay: 5
retries: 3
when: (cloud_load_balancer | bool and not database_public_access | bool) and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Enable public interface for Load Balancer"
hetzner.hcloud.load_balancer:
Expand All @@ -619,16 +691,18 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
register: hetzner_load_balancer_enable_public
until: hetzner_load_balancer_enable_public is success
delay: 5
retries: 3
when: (cloud_load_balancer | bool and database_public_access | bool) and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Add servers to Load Balancer (use label_selector 'cluster={{ patroni_cluster_name }}')"
hetzner.hcloud.load_balancer_target:
Expand All @@ -641,12 +715,14 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
when: cloud_load_balancer | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Gather information about Load Balancers"
hetzner.hcloud.load_balancer_info:
Expand Down Expand Up @@ -759,12 +835,14 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
when: cloud_load_balancer | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Delete Load Balancer"
hetzner.hcloud.load_balancer:
Expand All @@ -776,12 +854,14 @@
- "primary"
- "replica"
- "sync"
- "lb"
loop_control:
label: "{{ patroni_cluster_name }}-{{ item }}"
when: cloud_load_balancer | bool and
(item == 'primary' or
(item == 'replica' and server_count | int > 1) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool))
((item == 'primary' and not cloud_load_balancer_unified | bool) or
(item == 'replica' and server_count | int > 1 and not cloud_load_balancer_unified | bool) or
(item in ['sync', 'async'] and server_count | int > 1 and synchronous_mode | bool and not cloud_load_balancer_unified | bool) or
(item == 'lb' and cloud_load_balancer_unified | bool))

- name: "Hetzner Cloud: Delete public firewall"
hetzner.hcloud.firewall:
Expand Down
Loading