Dynamically Lists Server Backend

Can I dynamically lists all servers backend using lua scripts ? For Example:

Lua Script:

local function choose_backend()
return “server webserver02 lbwebserver-02.perf.lokal:80 check”
end
core.register_fetches(“choose_backend”, choose_backend)

HA Configuration:

global
    .... 
    lua-load /usr/sbin/lua-choose-backend.lua

defaults
    ....

frontend WEBSERVERS
    bind 172.18.69.116:9000
    use_backend WEBSERVER01

backend WEBSERVER01
    %[lua.choose_backend]

I had tried that thing, but haproxy says invalid ‘%’ thing.
I don’t want to use the ‘use_backend’ like internet says, because If I use that way, I would have to add the backends everytime my servers grow. I want to dynamically list those servers on the lua

Is that possible ?

No, that is not how it works at all.

The configuration is parsed at startup, you cannot generate a configuration at runtime in LUA and then feed haproxy with it. That doesn’t work and never will.

Can you explain more thoroughly what you are trying to achieve?

1 Like