Search code examples
haproxysalt-project

How do I target a Load Balancer with a terminal command ran on another minion via a .sls file in saltstack?


I have a 6 webserver one load balancer configuration. I want the webserver to be disabled on the loadbalancer while the website content is being updated. I want this done in a rolling fashion across all minions. Eg: Minion1 is be maintained, minion1 is disabled on the LB and once the maintenance is done minion1 is enabled again, while saltstack moves on to minion2 and the process is repeated. I want to use something like this echo "disable server backend/servername | socat stdio /etc/haproxy/haproxysock" where servername would be the minion that is being maintained, but this command has to be run on the haproxy LB each time. Once before maintenance takes place to disable the webserver and again after the maintenance to enable the webserver again. Any help would be much appreciated.


Solution

  • You could build your solution using the reactor system like dahrens mentioned.

    You might look at using the orchestrate runner found here: https://docs.saltstack.com/en/latest/topics/tutorials/states_pt5.html#orchestrate-runner

    This would allow you to orchestrate a rolling update like you want very nicely.

    If you want to do this from a regular Salt state you could use the batch option on the cli to update one server at a time and use the prereq to remove the current server from the load balancer during the update.