HA Proxy Ansible Role https://www.haproxy.org/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-13 10:37:10 +00:00
.forgejo/workflows fix: updated pipeline + tni git 2026-10-12 16:43:59 +07:00
defaults feat: added multiple ips per entry 2026-10-28 00:41:32 +01:00
handlers feat: first running version 2026-04-24 12:20:12 +02:00
meta feat: first running version 2026-04-24 12:20:12 +02:00
tasks feat: added check http for http health checks 2026-11-13 11:36:58 +01:00
templates feat: added check http for http health checks 2026-11-13 11:36:58 +01:00
.gitignore feat: first running version 2026-04-24 12:20:12 +02:00
CHANGELOG.md feat: added check http for http health checks 2026-11-13 11:36:58 +01:00
LICENSE feat: first running version 2026-04-24 12:20:12 +02:00
README.md Prettified Code! 2026-11-13 10:37:10 +00:00

HAProxy

Installs and configures HAProxy as a layer-7 domain-based reverse proxy, routing HTTP and HTTPS traffic to backends by hostname.

Requirements

None.

Variables

Variable Default Description
ha_connections [] List of backend routing rules. Required (must be non-empty). See Connections below.
ha_uninstall false Stops, disables, and purges HAProxy.

Connections

Each entry in ha_connections defines one backend:

Key Required Description
urls Yes List of hostnames to route to this backend.
ip Yes* Backend IPv4 address (*or ips).
is_fallback No If true, this backend receives all traffic that matches no other rule. At most one entry may be true.
proxy_protocol No If false, don't send PROXY protocol v2 to this backend (default true). See Notes — only for backends with no PROXY protocol support.
allowed_sources No List of client IPs/CIDRs allowed to reach this backend (default: everyone). Others are rejected by HAProxy itself: TCP reject on 443, HTTP 403 on 80. Applies to all urls of the entry.
ips No Several backend IPv4 addresses instead of ip: leastconn balancing with health checks (TCP connect by default).
http No backend (default) forwards port 80 to the backend(s); redirect answers it with a 301 to https.
check_http No With ips: health-check over HTTPS instead of TCP, so a node whose reverse proxy answers but whose app is down drops out. Keys: path (default /), host (Host header and SNI, default the first of urls), status (expected, default 200). The certificate isn't verified.

TCP services

ha_tcp_services adds plain TCP frontends (e.g. SMTP/IMAP), one frontend and backend per entry:

Key Required Description
name Yes Service name, letters/digits/_/-.
port Yes Listen port. Not 80/443, those are the HTTP/SNI frontends.
servers Yes Backend IPv4 addresses, PROXY protocol v2 and health checks.
server_port No Backend port, defaults to port.
bind No Addresses to listen on, default ['*']. Addresses the host does not have are dropped with a warning instead of making HAProxy fail to start.
proxy_protocol No Send PROXY protocol v2, default true.
timeout No Client/server idle timeout, default 1h.

Usage

Minimal setup:

ha_connections:
  - urls:
      - example.com
      - www.example.com
    ip: 1.2.3.4

With a fallback backend:

ha_connections:
  - urls:
      - app.example.com
    ip: 1.2.3.4
  - urls:
      - other.example.com
    ip: 5.6.7.8
    is_fallback: true

Uninstall

To stop, disable, and purge HAProxy:

ha_uninstall: true

Notes

  • Both HTTP (:80) and HTTPS (:443) frontends are configured. HTTPS routing uses TCP mode with SNI inspection — TLS is not terminated at HAProxy.
  • Backends use PROXY protocol v2 (send-proxy-v2) by default to forward the original client IP. Because HTTPS is TCP-passthrough (no TLS termination), this is the only way a backend learns the real client IP — there's no X-Forwarded-For fallback. The backend must explicitly trust and parse it (e.g. Traefik with entryPoints.*.proxyProtocol.trustedIPs set to this host's IP) or the connection will be silently dropped. Set proxy_protocol: false on a connection if its backend has no PROXY protocol support at all.
  • The generated config is validated with haproxy -c -f before being applied. HAProxy is reloaded gracefully on config change.