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:
Groups:
Load balancer
Web server
Database
Nodes:
Minion1
Minion2
Minion3
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 beinstalled
as well as what needs to bepurged
.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.