More Salt Notes – Targeting Minions

Use Salt to Manage all of your Salt Minions

Use Salt to Manage all of your Salt Minions

In an earlier article (Puppet, Chef, and now Salt for Configuration Management), we discussed how to install salt for configuration management.  At the end of the article, we discussed running command on the minions using the salt command from the salt master.  So, as I have worked with salt ever since, I have been looking for newer and better ways to address the specific minions individually or in groups to control the minions more effectively.

How to Target All Salt Minions

Sometimes, you want to address all of your minions at once.  You can do this using the asterisk(*).  Remember to use quotes with wildcard characters and salt or it won’t work as shown below:

$ salt * uptime
No minions matched the target. No command was sent, no jid was assigned.

So, below, we will quote our wildcard.  It is a good idea to use quotes whenever using wildcard characters so that the shell doesn’t intrepret the wildcard, but salt does.

$ salt "*" "uptime"
15:32:09 up 22 days, 23:39, 0 users, load average: 0.31, 0.28, 0.21
15:32:09 up 18 days, 22:17, 0 users, load average: 0.00, 0.02, 0.05

Target a Command at a Specific Salt Minion

You can easily target a specific minion by name.  Remember from our prior article that you can list your minions on the salt master first to get a list of the minions’ names.

$ salt-key -L
Accepted Keys:
Unaccepted Keys:
Rejected Keys:

Now use the name of your minion from the list to target the specific minion:

$ salt

We can also specify multiple minions specifically by name:

$ salt -L ','

Using Wildcards to Target All Salt Minion Hosts in a Domain

We now go back to using wildcards to match the names of the minions

Example:  Using the * wildcard to target all hosts / subdomains in a domain

$ salt '*' uptime
15:49:33 up 22 days, 23:57, 0 users, load average: 0.18, 0.23, 0.19
15:49:33 up 18 days, 22:34, 0 users, load average: 0.00, 0.01, 0.05

Using Other Wildcards to Target Salt Minions:

Example:  Using the ? single character wildcard to target specific salt minions

$ salt 'www?' uptime
16:02:46 up 23 days, 10 min, 0 users, load average: 0.14, 0.22, 0.19
16:02:46 up 18 days, 22:47, 0 users, load average: 0.00, 0.01, 0.05


$ salt 'www[1-2]' uptime
16:03:00 up 23 days, 10 min, 0 users, load average: 0.26, 0.24, 0.20
16:02:46 up 18 days, 22:47, 0 users, load average: 0.00, 0.01, 0.05

Group Target Minions using Salt Nodegroups

Using nodegroups (defined in the top_file)

In the salt master’s configuration file (/etc/salt/master on my salt master) you can specify and define groups of nodes into salt “nodegroups”.  You can use any of the mechanisms in this article to create your nodegroup definitions.

Example:  Four nodegroups have been defined in the salt master’s /etc/salt/master file

allofuptime: '*'
uptimedbs:   'db?'
uptimewwws:  'www?'
specificminions:  ','

Now use the -N option to specify the nodegroup when you run the command.

Example:  Using a nodegroup as a target of a salt command from the salt master

# salt -N uptimedbs "uptime"
16:15:41 up 23 days, 23 min, 0 users, load average: 0.33, 0.23, 0.19
16:15:41 up 18 days, 23:00, 0 users, load average: 0.00, 0.01, 0.05

Use Grains to Target Salt Minions

I will be writing another article explaining how to get the most out of grains in the next couple of days.  You may want to refer to it when it is released.  Until that article is out, what you really need to know about grains is that they are static definitions about a specific host.  For example a minion’s grains would be static properties about that specific host.  Some grain examples would be a minion’s operating system, cpu architecture, eth0 mac address, etc…  By using a grain as a target, we are able to further group our minions.  Using a grain to target a salt minion will allow you to install a certain package on all of your Ubuntu Linux machines using apt-get in one command or maybe update all of your CentOS systems in one command.

Example:  using an OS grain to target all Fedora based systems for package updates.

$ salt -G 'os:Fedora' "yum update -y"

Example: using the kernel grain to find the ipaddresses of all Linux Minions

$ salt -G 'kernel:Linux' grains.item fqdn_ip4

As you can see the methods at your disposal for targeting your salt minions is almost limitless.  There are many other resources where you can go for examples and help.  Probably the best location is the salt documentation itself which can be found here:


The following two tabs change content below.
Jeff has 20 years of professional IT experience, having done nearly everything in his roles of IT consultant, Systems Integrator, Systems Engineer, CNOC Engineer, Systems Administrator, Network Systems Administrator, and IT Director. If there is one thing he knows for sure, it is that there is always a simple answer to every IT problem and that downtime begins with complexity. Seasoned IT professional by day, Jeff hopes to help other IT professionals by blogging about his experiences at night on his blog: You can find Jeff on or LinkedIn at: LinkedIn or Twitter at: Twitter

Latest posts by Jeff Staten (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *