The ansible-role-haproxy-setup role allows for the simple, flexible, and declarative installation and configuration of HAProxy, with the integrated Prometheus exporter. Thanks to a clear YAML structure, users can effortlessly define their global, defaults, frontends, backends, and stats blocks, while maintaining full control over advanced HAProxy options.
- Red Hat or Debian distributions using systemd as the service manager.
- HAProxy version >= 2.6
| Name | Type | Description | Mandatory | Default value |
|---|---|---|---|---|
haproxy_version |
str | HAProxy version to install. Format: x.y or x.y.z | no | "2.8" |
haproxy_use_full_version |
bool | indicates whether to force the use of a full version of haproxy in x.y.z format | no | false |
haproxy_use_community_repo |
bool | indicates whether the use of a community repository for haproxy should be enforced | no | false |
haproxy_repo_community |
str | definition of the community repository: URL, PPA, or an APT signed-by option | no | "" |
haproxy_repo_package_name |
str | The name of the haproxy package in a specific repository: if not mentioned, then the string haproxy will be used. |
no | "" |
haproxy_repo_dependencies |
list(str) | dependency packages to install before installing HAProxy | no | [] |
haproxy_repo_keyring_url |
str | the URL of the repository's gpg key | no | "" |
haproxy_repo_keyring_path |
str | the full path to the downloaded gpg key file from the repository | no | "" |
haproxy_frontend_ssl_enable |
bool | indicates whether to allow the creation of the certificate directory and upload the certificate files to be entered in the frontend blocks | no | false |
haproxy_frontend_ssl_certificates |
list(dict) | allows you to specify a list of certificates to upload, where each item is a dictionary of keys: src_filename and dest_filename |
no | [] |
haproxy_frontend_ssl_certificates[].src_filename |
str | relative or full path of the certificate file to upload | yes | `` |
haproxy_frontend_ssl_certificates[].dest_filename |
str | relative or full path to the destination location of the certificate file to be uploaded | yes | `` |
haproxy_config_global |
dict | global configuration dictionary | yes | `` |
haproxy_config_global.enable_zero_warning |
bool | the haproxy_config_global key to enable the zero_warning option |
no | true |
haproxy_config_global.maxconn |
int | the haproxy_config_global key used to configure the maxconn option |
no | 4000 |
haproxy_config_global.logs |
list(str) | The haproxy_config_global key allows configuration of the log option lines. |
no | depending on the distribution |
haproxy_config_global.stats_socket_configs |
list(str) | the haproxy config global key allows you to configure the stats socket lines. |
no | [] |
haproxy_config_global.security_ssl_policies |
list(str) | the haproxy_config_global key used to configure SSL security policies |
no | `` |
haproxy_config_global.custom_options |
list(str) | the haproxy_config_global key used to configure custom options |
no | `` |
haproxy_config_defaults |
list(dict) | configuration list of defaults blocks |
no | [] |
haproxy_config_defaults[].name |
str | unique name of a defaults block |
yes | `` |
haproxy_config_defaults[].custom_options |
list(str) | list of custom options for a defaults block |
yes | `` |
haproxy_config_frontends |
list(dict) | configuration list of frontend blocks |
no | [] |
haproxy_config_frontends[].name |
str | unique name of a frontend block |
yes | `` |
haproxy_config_frontends[].binds |
list(str) | list of bind options for a frontend block |
yes | `` |
haproxy_config_frontends[].from_default |
str | name of a default block defaults for a frontend block |
no | "" |
haproxy_config_frontends[].default_backend |
str | name of a default backend for a frontend block |
no | "" |
haproxy_config_frontends[].custom_options |
list(str) | list of custom options for a frontend block |
no | [] |
haproxy_config_backends |
list(dict) | configuration list of backend blocks |
no | [] |
haproxy_config_backends[].name |
str | unique name of a backend block |
yes | `` |
haproxy_config_backends[].from_default |
str | name of a default block defaults for a backend block |
no | "" |
haproxy_config_backends[].servers |
list(str) | list of server options for a backend block |
yes | `` |
haproxy_config_backends[].custom_options |
list(str) | list of custom options for a backend block |
no | [] |
haproxy_config_stats |
dict | configuration dictionary for the statistical service block | yes | `` |
haproxy_config_stats.enable |
bool | the haproxy_config_stats key indicates whether to enable the statistics service. |
no | true |
haproxy_config_stats.name |
str | the key of haproxy_config_stats for the statistical service block name |
yes | `` |
haproxy_config_stats.from_default |
str | the key for haproxy_config_stats is the name of a default block, and defaults is the block name for the statistics service. |
no | "" |
haproxy_config_stats.bind |
str | the haproxy_config_stats key specifies the listening port for the statistics service. |
yes | `` |
haproxy_config_stats.uri |
str | the haproxy_config_stats key specifies the URI of the statistics service. |
no | "/stats" |
haproxy_config_stats.exporter_enable |
bool | the haproxy_config_stats key to enable or disable the Prometheus exporter at the statistics service level |
no | true |
haproxy_config_stats.exporter_path |
str | the haproxy_config_stats key to configure the Prometheus exporter URI at the statistics service level |
no | "/metrics" |
haproxy_config_stats.custom_options |
list(str) | the haproxy_config_stats key is used to configure custom options for the statistics service. |
no | [] |
Note: To configure a
RedHatdistribution repository (the variables:haproxy_repo_community,haproxy_repo_keyring_urlorhaproxy_repo_package_name), please refer to the site https://github.com/haproxy/wiki/wiki/Packages.
Note: To configure a repository for
Debiandistributions (the variables:haproxy_repo_community,haproxy_repo_keyring_url,haproxy_repo_keyring_pathorhaproxy_repo_dependencies), please refer to the website https://haproxy.debian.net/.
None.
- Role installation
mkdir -p $HOME/install-haproxyvim $HOME/install-haproxy/requirements.yml- name: ansible-role-haproxy-setup
src: git+https://github.com/willbrid/ansible-role-haproxy-setup.git
version: v0.0.1cd $HOME/install-haproxy && ansible-galaxy install --force -r requirements.ymlNote: It is assumed that a
hosts.inifile (in the$HOME/install-haproxydirectory) is defined, containing the inventory of groupserverservers, usingDebianorRedHatdistributions.
Note: It is assumed that a
filesdirectory (in the$HOME/install-haproxydirectory) is defined and contains aserver.crtfile.
- Using the role in a playbook
vim $HOME/install-haproxy/playbook.yml--- Example of the playbook.yml file content for Rocky Linux 9
---
- hosts: server
become: true
vars:
haproxy_version: "2.8"
haproxy_use_full_version: false
haproxy_use_community_repo: true
haproxy_frontend_ssl_enable: true
haproxy_frontend_ssl_certificates:
- {src_filename: "files/server.crt", dest_filename: "server.crt"}
haproxy_repo_community: "https://packages.zenetys.com/latest/redhat/$releasever/RPMS/$basearch"
haproxy_repo_keyring_url: "https://packages.zenetys.com/RPM-GPG-KEY-ZENETYS-ZLAB-Packaging-v1"
haproxy_repo_package_name: "haproxy28z"
haproxy_config_defaults:
- name: "http"
custom_options:
- "mode http"
- "option httplog"
- "log global"
- "timeout client 1m"
- "timeout server 1m"
- "timeout connect 10s"
- "timeout http-keep-alive 2m"
- "timeout queue 15s"
haproxy_config_frontends:
- name: "frontend_site1"
binds:
- "*:8000"
from_default: "http"
default_backend: "backend_site1"
- name: "frontend_site2"
binds:
- "*:8080"
- "*:8443"
from_default: "http"
default_backend: "backend_site2"
custom_options:
- "mode http"
haproxy_config_backends:
- name: "backend_site1"
from_default: "http"
servers:
- "server site1-web 127.0.0.1:8081 check"
- name: "backend_site2"
from_default: "http"
custom_options:
- "balance roundrobin"
servers:
- "server site2-web1 127.0.0.1:8084 check"
- "server site2-web2 127.0.0.1:8085 check"
- "server site2-web3 127.0.0.1:8086 check"
roles:
- ansible-role-haproxy-setup--- Example of the playbook.yml file content for Debian 12
- hosts: server
become: true
vars:
haproxy_version: "2.8"
haproxy_use_full_version: false
haproxy_use_community_repo: true
haproxy_frontend_ssl_enable: false
haproxy_frontend_ssl_certificates: []
haproxy_repo_community: "deb [signed-by=/usr/share/keyrings/haproxy-archive-keyring.gpg] http://haproxy.debian.net bookworm-backports-2.8 main"
haproxy_repo_keyring_url: "https://haproxy.debian.net/haproxy-archive-keyring.gpg"
haproxy_repo_keyring_path: "/usr/share/keyrings/haproxy-archive-keyring.gpg"
haproxy_config_defaults:
- name: "http"
custom_options:
- "mode http"
- "option httplog"
- "log global"
- "timeout client 1m"
- "timeout server 1m"
- "timeout connect 10s"
- "timeout http-keep-alive 2m"
- "timeout queue 15s"
haproxy_config_frontends:
- name: "frontend_site1"
binds:
- "*:8000"
from_default: "http"
default_backend: "backend_site1"
- name: "frontend_site2"
binds:
- "*:8080"
- "*:8443"
from_default: "http"
default_backend: "backend_site2"
custom_options:
- "mode http"
haproxy_config_backends:
- name: "backend_site1"
from_default: "http"
servers:
- "server site1-web 127.0.0.1:8081 check"
- name: "backend_site2"
from_default: "http"
custom_options:
- "balance roundrobin"
servers:
- "server site2-web1 127.0.0.1:8084 check"
- "server site2-web2 127.0.0.1:8085 check"
- "server site2-web3 127.0.0.1:8086 check"
roles:
- ansible-role-haproxy-setup--- Example of the content of the playbook.yml file for Debian 11
- hosts: server
become: true
vars:
haproxy_version: "2.8"
haproxy_use_full_version: false
haproxy_use_community_repo: true
haproxy_frontend_ssl_enable: false
haproxy_frontend_ssl_certificates: []
haproxy_repo_community: "deb [signed-by=/usr/share/keyrings/haproxy-archive-keyring.gpg] http://haproxy.debian.net bullseye-backports-2.8 main"
haproxy_repo_keyring_url: "https://haproxy.debian.net/haproxy-archive-keyring.gpg"
haproxy_repo_keyring_path: "/usr/share/keyrings/haproxy-archive-keyring.gpg"
haproxy_config_defaults:
- name: "http"
custom_options:
- "mode http"
- "option httplog"
- "log global"
- "timeout client 1m"
- "timeout server 1m"
- "timeout connect 10s"
- "timeout http-keep-alive 2m"
- "timeout queue 15s"
haproxy_config_frontends:
- name: "frontend_site1"
binds:
- "*:8000"
from_default: "http"
default_backend: "backend_site1"
- name: "frontend_site2"
binds:
- "*:8080"
- "*:8443"
from_default: "http"
default_backend: "backend_site2"
custom_options:
- "mode http"
haproxy_config_backends:
- name: "backend_site1"
from_default: "http"
servers:
- "server site1-web 127.0.0.1:8081 check"
- name: "backend_site2"
from_default: "http"
custom_options:
- "balance roundrobin"
servers:
- "server site2-web1 127.0.0.1:8084 check"
- "server site2-web2 127.0.0.1:8085 check"
- "server site2-web3 127.0.0.1:8086 check"
roles:
- ansible-role-haproxy-setup--- Example of the playbook.yml file content for Ubuntu 24.04
- hosts: server
become: true
vars:
haproxy_version: "2.8"
haproxy_use_full_version: false
haproxy_use_community_repo: false
haproxy_frontend_ssl_enable: false
haproxy_frontend_ssl_certificates: []
haproxy_config_defaults:
- name: "http"
custom_options:
- "mode http"
- "option httplog"
- "log global"
- "timeout client 1m"
- "timeout server 1m"
- "timeout connect 10s"
- "timeout http-keep-alive 2m"
- "timeout queue 15s"
haproxy_config_frontends:
- name: "frontend_site1"
binds:
- "*:8000"
from_default: "http"
default_backend: "backend_site1"
- name: "frontend_site2"
binds:
- "*:8080"
- "*:8443"
from_default: "http"
default_backend: "backend_site2"
custom_options:
- "mode http"
haproxy_config_backends:
- name: "backend_site1"
from_default: "http"
servers:
- "server site1-web 127.0.0.1:8081 check"
- name: "backend_site2"
from_default: "http"
custom_options:
- "balance roundrobin"
servers:
- "server site2-web1 127.0.0.1:8084 check"
- "server site2-web2 127.0.0.1:8085 check"
- "server site2-web3 127.0.0.1:8086 check"
roles:
- ansible-role-haproxy-setup--- Example of the playbook.yml file content for Ubuntu 22.04
- hosts: server
become: true
vars:
haproxy_version: "2.8"
haproxy_use_full_version: false
haproxy_use_community_repo: true
haproxy_frontend_ssl_enable: false
haproxy_frontend_ssl_certificates: []
haproxy_repo_community: 'ppa:vbernat/haproxy-2.8'
haproxy_repo_dependencies: ["software-properties-common", "dirmngr"]
haproxy_config_defaults:
- name: "http"
custom_options:
- "mode http"
- "option httplog"
- "log global"
- "timeout client 1m"
- "timeout server 1m"
- "timeout connect 10s"
- "timeout http-keep-alive 2m"
- "timeout queue 15s"
haproxy_config_frontends:
- name: "frontend_site1"
binds:
- "*:8000"
from_default: "http"
default_backend: "backend_site1"
- name: "frontend_site2"
binds:
- "*:8080"
- "*:8443"
from_default: "http"
default_backend: "backend_site2"
custom_options:
- "mode http"
haproxy_config_backends:
- name: "backend_site1"
from_default: "http"
servers:
- "server site1-web 127.0.0.1:8081 check"
- name: "backend_site2"
from_default: "http"
custom_options:
- "balance roundrobin"
servers:
- "server site2-web1 127.0.0.1:8084 check"
- "server site2-web2 127.0.0.1:8085 check"
- "server site2-web3 127.0.0.1:8086 check"
roles:
- ansible-role-haproxy-setup- Playbook execution
cd $HOME/install-haproxy && ansible-playbook -i hosts.ini playbook.ymlMIT
William Bridge NGASSAM