HAProxy Enterprise can read environment variables at startup.
One way to add environment variables is by appending them to the Environment line in the file /lib/systemd/system/hapee-1.6-lb.service. Then HAProxy Enterprise will have access to them when it starts up as a service.
In the following example, we append an environment variable named PROXYNAME to the Environment line:
"CONFIG=/etc/hapee-1.6/hapee-lb.cfg" "PIDFILE=/run/hapee-1.6-lb.pid" "PROXYNAME=lb1"
We then use the
env fetch method to read the environment variable from the HAProxy Enterprise configuration. Here, we retrieve the value of the PROXYNAME environment variable to use in the Via HTTP request header:
frontend www bind :80 # Uses the value from the environment, 'lb1' http-request add-header Via "%[req.ver] %[env(PROXYNAME)]"
Set a new variable or override an existing one
You can also set environment variables from the HAProxy Enterprise configuration. The
setenv directive in the
global section sets a new or overrides an existing environment variable.
For example, you can override the PROXYNAME variable with this configuration:
global setenv PROXYNAME lb2 frontend www bind :80 # Uses the overridden value, 'lb2' http-request add-header Via "%[req.ver] %[env(PROXYNAME)]"
Alternatively, use the
presetenv directive to set an environment variable. In this case, if that variable is already set, it will not be overridden:
global presetenv PROXYNAME lb2 frontend www bind :80 # Uses the value from the environment if it was set, 'lb1', otherwise, it uses 'lb2' http-request add-header Via "%[req.ver] %[env(PROXYNAME)]"
Next upReference Manual