[FEATURE REQUEST] Run local SLS file automatically on reboot, without going masterless!
Is your feature request related to a problem? Please describe.
My organization has a backup site failover issue that could be solved with Salt.
When our Windows minions failover to our backup site B, they are first powered down at site A, they then lose their original IP address and get a new one when they are powered back up at site B. In order to get back on the network and reconnect with the master and everything else they need "ipconfig /registerdns" ran.
Describe the solution you'd like
I am aware of masterless mode, but it turns off its ability and duty to talk to the master for instructions entirely, and goes totally headless.
What I need: When the server is powered back on and subsequently the salt agent is started, I need to run a local SLS file that runs "ipconfig /registerdns" with cmd.run, which will restore DNS and finally get everything it needs from the master. So I guess it's kind of a hybrid of local and remote working together?
Describe alternatives you've considered
I've tried different combinations of minion config file changes in hopes that the functionality is hidden in plain site, but I have struck out.
This is just one scenario, but I have many more situations that would benefit from this feature. Or, does it already exist and I'm just not seeing it?
Thanks in advance,
Greg
You can run salt with an alternative config location, -c, in combination with the usual salt-call --local. This would allow you to specify an alternative config for your bootstrap state, as well as your standard config for master mode. Is that what you're looking for?
It might be, can you give me an example? I've never heard of -c alternate configs.
I just need 1 sls file to run when the server powers back on, regardless of whether or not the minion can talk to the master. So I can't be doing any manual salt-call commands, not sure if that's a part of what you're getting at. It all has to happen automatically.
Thanks again,
Greg
If you need to run such command on startup, then maybe it would be better not to force Salt to run it, but force Salt to configure actual startup script on your system?
Yes, that is what I'll be doing if I can't find a smooth way for Salt to handle it entirely on its own. Thanks for your input, it reinforces what I am planning as a last resort.
@evenyougreg to be honest, I've never thought of such usecase as yours, since SaltStack is mostly management configuration ;) (apart from other nice stuff of couse) When I wanted to configure something at start of system, I always used Salt to configure startup instead of making Salt of doing things like that. Mainly, because you can't rely on it always because - as you said - master may be unavailable.
But managing startup script seems more Salty than actually executing ipconfig /registerdns alone without any reason (as it looks from the description).
I just need 1 sls file to run when the server powers back on, regardless of whether or not the minion can talk to the master. So I can't be doing any manual salt-call commands, not sure if that's a part of what you're getting at. It all has to happen automatically.
Oh okay that's even easier then. You just need to run have the state.sls on your machine, then use state.template:
salt-call --local state.template /path/to/local/state.sls.
The reason I suggested a second config was because I assumed you wanted a more complicated masterless setup, but the above would be good enough for a single state file.
Of course you'll need some way to run this command automatically at startup (perhaps every 'x' minutes is better). I suggest systemd on most linux machines, or the windows scheduled task manager.
@evenyougreg We have a little utility package that we've been working on to support use-cases like this. We're using it pretty aggressively. See https://github.com/f0cal/saltbox
@evenyougreg could use the salt module win_task. win_task works with Windows Task Scheduler so you can tell windows to run a ‘salt-call’ every time windows boots back up.
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.win_task.html
Thanks @cmcmarrow, I appreciate the input. I'm trying to avoid intervention/help outside of Salt software, which is why I was posting as a feature request. Seems like an obvious thing that could be built into Salt.