Saltstack's execution modules allows you to run specific modules written in python that will conduct system management tasks on remote servers. What does this mean? Let's say you want to upgrade all of your Linux servers, instead of going to each host and using the upgrade command, you can bang it all out with a simple execution module.
Today I'll show you some common execution modules in Saltstack. Before you read any further, take a moment to take a peak at all of the execution modules available in Saltstack.
Let's Get Started
Updating installed packages
So I previously mentioned that there is a module to upgrade all of your packages similar to running
yum upgradecommand. We'll take a look at that first! Jump into your Salt Master server now.
The module we will be working with is pkg. To install the upgrades execute the command below. (NOTE: * indicates that you are targeting all of the host registered to the salt master)
salt '*' pkg.upgrade
This command tells the salt-master to target every host it knows about and execute the upgrade command. Now, depending on the amount of packages that need to be upgraded, this can take a while.
Now let's say you want to see which packages will be upgrade and from that output you can decide if you want to upgrade it or not. To do this you need to use the 'dryrun' option.
salt '*' pkg.upgrade dryrun=True
This won't upgrade anything but it will output all of the packages that will be upgraded if you ran this for real.
From the information above you can individually upgrade packages with the following command:
salt '*' pkg.upgrade vim
Let's look at another module with a different scenario...
In this second scenario, we'll pretend that you want to zip up the hosts file. However you may have noticed, that there is no execution module for zipping up files. That is okay, we can still execute Linux commands using Saltstack!
To execute Linux commands on a remote host, we can use the
cmd.shell module and then supply it with the command we want Saltstack to execute on the remote host.
salt '*' cmd.shell 'gzip /etc/hosts'
That is pretty much all to it with Saltstacks execution modules, but before I let you all go and play with Saltstack, let me explain targeting specific hosts.
So in the previous examples I was globing all of my hosts with
*. The * tells Saltstack to target all of the hosts it knows about and execute the module on them. Now what happens if you only want to target specific hosts? You can use the
-L to list specific host that you want Saltstack to interact with.
salt -L 'host1,host2,host3' pkg.upgrade
The command above will tell Saltstack to upgrade the packages on host1, host2, and host3 only.
You can also target large amounts of hosts with similar names (ie: host1, host2...host100) with globbing.
salt 'host*' pkg.upgrade
Okay that is it, have fun and explore Saltstack! Also if you're wondering how to install Saltstack, checkout our youtube video here.
** NOTE: 12/14/2018 - Earlier I mentioned
pkg.upgrade updates packages, I have re-read the docs and corrected my mistakes. In fact it is equivalent to
yum upgrade and NOT
yum update. DOCS **