SaltStack Crash Course
What is SaltStack?⌗
SaltStack is a configuration management tool.
It allows you to manage thousands of servers (or just one) from a central location.
This post will help you getting started with several VMs you can use to get to know SaltStack. After you’ve followed these instructions, you will get one Salt Master and 2 Salt Minions on which you can execute your commands.
Prerequisites⌗
Getting Started⌗
The first time you execute vagrant up
it might take several minutes, depending on your internet connection. Subsequent executions will be much faster since the boxes will be cached on your local machine.
After the VMs started successfully, you can connect to the Salt master via
Salt commands on this machine require sudo permissions, so switch to root via
Now you can execute salt commands. Let’s try an execution module, test.ping on all VMs:
SaltStack can issue commands two different ways, via execution modules and via state modules.
Modules can be called for any machine via the Salt master, or for the local machine via salt-call
.
Salt CLI⌗
Salt State Modules⌗
SaltStack files are written (per default) in YAML.
The top.sls
for state modules consists of 3 elements and is used to target specific minions with specific states.
A state consists of an ID (that is unique across all state modules), the module to execute and its parameters.
With 2 files (top.sls
and my_own_git_state.sls
) inside salt/roots/ you can now go ahead and execute
This will now make sure that git is installed on all 3 machines. On the master git is already installed, hence SaltStack will not change anything. On the two minions however git alongside its dependencies will be installed via apt-get. Now imagine you do not only want git, but also a git repository cloned. This can be easily done by appending the git.latest state module to our state file so that it looks as follows:
And now let’s again apply the state to all VMs:
Further Reading⌗
If you want to know more, I recommend the excellent SaltStack Tutorials, which goes far more in-depth.