HA Proxy Ansible Role
https://www.haproxy.org/
- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| defaults | ||
| handlers | ||
| meta | ||
| tasks | ||
| templates | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| README.md | ||
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 noX-Forwarded-Forfallback. The backend must explicitly trust and parse it (e.g. Traefik withentryPoints.*.proxyProtocol.trustedIPsset to this host's IP) or the connection will be silently dropped. Setproxy_protocol: falseon a connection if its backend has no PROXY protocol support at all. - The generated config is validated with
haproxy -c -fbefore being applied. HAProxy is reloaded gracefully on config change.