/ configuration management

SaltStack Execution Modules

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 update 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 update all of your packages similar to running yum update command. 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 updates 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 package update command. Now, depending on the amount of packages that need to be updated, this can take a while.

Now let's say you want to see which packages will be updated and from that output you can decide if you want to install it or not. To do this you need to use the 'dryrun' option.

salt '*' pkg.upgrade dryrun=True

This won't update anything but it will output all of the packages that will need to be updated.

From the information above you can individually update 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'

Host Targeting

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.

SaltStack Execution Modules
Share this