TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/wikioasis/salt/llms.txt
Use this file to discover all available pages before exploring further.
haproxy Salt execution module provides runtime control of HAProxy directly through its Unix stats socket. Every function communicates with the running HAProxy process using socat — no configuration file edits, no haproxy reload, and no brief connection disruption. Changes made through this module take effect immediately and persist only until the next HAProxy restart unless you also update the pillar and re-apply the haproxy.route state.
Socket Configuration
The module reads the socket path fromhaproxy:stats_socket in pillar, with a default of /run/haproxy/admin.sock:
CommandExecutionError is raised if socat exits non-zero.
Functions
haproxy.status()
Returns the current state of all backend servers by parsing the output of the show stat HAProxy command. Frontend and backend aggregate rows are filtered out; only individual server rows are returned.
Returns: List of dicts, each with keys backend, server, status, and weight.
The
status field comes directly from HAProxy’s CSV stat output (column 18). Common values are UP, DOWN, MAINT (manually disabled via disable server), and DRAIN.haproxy.depool(backend, server)
Disables a server in the specified backend by sending disable server <backend>/<server> to the stats socket. Takes effect immediately with no reload. Existing connections to the server are allowed to complete (graceful drain); no new requests are routed to it.
The HAProxy backend name, e.g.
mediawiki.The server name as defined in the HAProxy configuration, e.g.
mw-us-east-011.<backend>/<server> depooled.
haproxy.repool(backend, server)
Re-enables a previously disabled server in the specified backend by sending enable server <backend>/<server> to the stats socket. Takes effect immediately.
The HAProxy backend name, e.g.
mediawiki.The server name as defined in the HAProxy configuration, e.g.
mw-us-east-011.<backend>/<server> repooled.
haproxy.route_list()
Returns all active hostname → backend mappings from the live HAProxy routes map (/etc/haproxy/routes.map) by parsing the output of show map /etc/haproxy/routes.map. The map is used by HAProxy’s ACLs to route requests from a given Host header to the correct backend.
Returns: Dict of hostname → backend.
The raw
show map output includes an internal pointer prefix (0x...) on each line. The module strips this and returns only the hostname and backend values.haproxy.route_set(hostname, backend)
Adds or updates a hostname → backend mapping in the live routes map. If the hostname already exists, the old entry is removed first (via del map) and the new one is added (via add map). The change takes effect immediately for all new connections.
The virtual hostname to route, e.g.
app.example.com. Must match the Host header sent by clients.The HAProxy backend name to route the hostname to, e.g.
mediawiki.<hostname> -> <backend>.
haproxy.route_del(hostname)
Removes a hostname route from the live routes map by sending del map /etc/haproxy/routes.map <hostname> to the stats socket. Takes effect immediately; requests to the deleted hostname will no longer match the map entry.
The virtual hostname to remove from the routes map, e.g.
app.example.com.<hostname> removed.
Runtime vs Persisted Changes
HAProxy holds the routes map in memory. Changes made through this module (route_set, route_del) update the in-memory map immediately but are lost on HAProxy restart.
To make a route change permanent, you must also update the pillar and apply the haproxy.route state:
haproxy.route state writes /etc/haproxy/routes.map from pillar, then on file change clears the live in-memory map and re-adds every active entry via the socket — again, no reload required.
| Method | Immediate | Survives restart |
|---|---|---|
haproxy.route_set / haproxy.route_del | ✅ Yes | ❌ No |
Update pillar + state.apply haproxy.route | ✅ Yes (via socket sync) | ✅ Yes |
Common Workflows
Depool a server before maintenance
Add a new wiki vhost route
Remove a decommissioned wiki route
haproxy.route to prevent it coming back on restart.