This role is for installing and configuring HAProxy. HAProxy is a load balancer for PostgreSQL.
Following are the requirements of this role.
- Ansible
edb_devops.edb_postgres
->setup_repo
role for setting the repository on the systems.
Which port to listen on. Applies to both TCP and Unix sockets. Default: 5000
Example:
haproxy_port: 5000
Specifies a list of addresses where to listen for TCP connections. You may also
use *
meaning “listen on all addresses”. Addresses can be specified
numerically (IPv4/IPv6) or by name. Default: *
Example:
haproxy_listen_address: "*"
The maxconn value that will be set in the global HAProxy configuration. Default: 100
Example:
haproxy_global_maxconn: "300"
If set to true
, HAProxy will configure a backend to route read-only connections to replicas.
Default: false
Example:
haproxy_read_only_lb: true
If haproxy_read_only_lb: true
, the port HAProxy will listen to for read-only connections.
Default: 5001
Example:
haproxy_replica_port: 5001
The port of the REST API of the patroni cluster.
Default: 8008
Example:
patroni_rest_api_port: 8008
This role does not have any dependencies, but packages repositories should have
been configured beforehand with the setup_repo
role.
HAProxy can be configured on any most node types. To configure HAProxy on a host,
set haproxy_configure
to true
. If you would like a host to be included as a backend server
to HAProxy, set haproxy: true
and include the proxy_location
of the proxy server the node
is a part of.
In this example, HAProxy is being configured alongside PgBouncer for a Patroni cluster.
Content of the inventory.yml
file:
---
all:
children:
pgbouncer:
hosts:
proxy1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
haproxy: true
proxy_location: 'zone_1'
haproxy_configure: true
primary:
hosts:
primary1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
haproxy: true
proxy_location: 'zone_1'
etcd: true
etcd_cluster_name: 'patroni-etcd'
Below is an example of how to include the setup_haproxy
role:
---
- hosts: all
name: Deploy haproxy
become: yes
gather_facts: yes
any_errors_fatal: true
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
set_fact:
pg_version: 15
pg_type: "PG"
roles:
- role: setup_repo
when: "'setup_repo' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: install_dbserver
when: "'install_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_etcd
when: "'setup_etcd' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_patroni
when: "'setup_patroni' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_pgbouncer
when: "'setup_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_haproxy
when: "'setup_haproxy' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: manage_pgbouncer
when: "'manage_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: manage_dbserver
when: "'manage_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
Defining and adding variables is done in the set_fact
of the pre_tasks
.
All the variables are available at:
BSD
Author:
- Hannah Stoik
- Vibhor Kumar (Reviewer)
- EDB Postgres
- [email protected] www.enterprisedb.com