I wonder to know if it is possible to install and remove packages when we change a state of node?
To clarify what I mean here is an example:

Load balancer
Web server


If we add Minion1 to the group "Web server" then we have to install Java and Tomcat server on it. If remove Minion1 from "Web server" group then we have to remove Java and Tomcat server from it. If we add Minion 2 to both groups "Load balancer" and "Database" then we have to install Nginx and MySQL. If we remove Minion2 from the group "Database" and add Minion2 to the "Web server" then we have to remove MySQL from it and install Java and Tomcat on it. And so on..

Is it possible to configure Salt to act like this? Maybe some alternatives?


You can set up each group to contain states that work with pkg states in such a way that they determine both what needs to be installed as well as what needs to be purged.

It does however seem like a strange approach. Typically if you want to replace a node, you remove the old virtual machine altogether, and instantiate a new virtual machine for the new role. That way you make sure things are clean and don't risk arbitrary changes to have been made that might interfere with the new role.

| improve this answer | |
  • Thank you for suggestion! But I don't have virtual machines. Only bare machines. Could you please show an example of such groups? – Oleksandr Apr 11 '17 at 12:55
  • The same logic works with physical machines - do a clean reinstall (using an automated method) and apply a different Salt state on top of it. If physical reinstall is too much of a hassle, I'd even suggest enabling virtualization and booting a single VM that gets all the resources of a physical server, just to be able to have everything unrelated to hardware nicely sequestered. – Josip Rodin Apr 11 '17 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.