Wednesday, 27 September 2017

SaltStack Targeting Methods - Glob Matching

So far, we have been targeting only one minion. When it comes to targeting a group of minions or all minions, there are certain ways to do it, which are listed as below:

  • Matching Minion IDs
    • Glob matching
    • PCRE
    • List matching
  • Matching with Grains
  • Matching with Pillars
  • IP address and Subnet Matching
  • Compound Matching


In this article, we will learn to target a subset of minions using Glob matching. For this, we have configured two minions with minion IDs centos-rack1 and redhat-rack2.

1. * matches anything


If you have worked with Linux files and directories, especially while removing all files with rm -f *, you might be familiar with globbing. When we specify *, we simple mean 'anything'. Thus, rm -f * in Linux removes all files in the directory. We can also mention *.pdf to remove files which have names - anything followed by .pdf.

Lets check it in Salt's context while targeting the minions.

$ salt '*' test.ping

centos-rack1:
    True
redhat-rack2:
    True

In above output, we can see the responses from all the minions, currently only two, are received on the master. If we were to target a particular minion, we should mention minion name in place of * as follows:

$ salt 'redhat-rack2' test.ping

redhat-rack2:
    True

Lets see more examples on this with descriptions mentioned in the comment.

2. ? matches one character


$ salt 'centos-rack?' test.ping
centos-rack1:
    True

3. * matches any character


$ salt '*-rack1' test.ping

centos-rack1:
    True

4. We can also mention range within square brackets


# Any letter between 'a' and 'm' followed by anything followed by '-rack' followed by anything
$ salt '[a-m]*-rack*' test.ping

centos-rack1:
    True

# Any letter between 'n' and 'z' followed by anything followed by '-rack' followed by anything 
$ salt '[n-z]*-rack*' test.ping

redhat-rack2:
    True


That's all for this article. These are several different types of targeting minions using glob matching, we have seen the basic ones. Glob matching is not the only option to target minions, there are few others too, as mentioned in earlier portion of this article. We will learn all of them one-by-one, in upcoming tutorials in the series.


0 comments:

Post a Comment