Compound matchers

Compound matchers allow very granular minion targeting using any of Salt's matchers. The default matcher is a glob match, just as with CLI and top file matching. To match using anything other than a glob, prefix the match string with the appropriate letter from the table below, followed by an @ sign.

Letter Delimiter Match Type Example
G x Grains glob G@os:Ubuntu
E   PCRE Minion ID E@web\d+\.(dev|qa|prod)\.loc
P x Grains PCRE P@os:(RedHat|Fedora|CentOS)
L   List of minions, or bl*
I x Pillar glob I@pdata:foobar
J x Pillar PCRE J@pdata:^(foo|bar)$
S   Subnet/IP address S@ or S@
R   Range cluster

Matchers can be joined using boolean and, or, and not operators.

For example, the following string matches all Debian minions with a hostname that begins with webserv, as well as any minions that have a hostname which matches the regular expression web-dc1-srv.*:

salt -C 'webserv* and G@os:Debian or E@web-dc1-srv.*'

That same example expressed in a top file looks like the following:

  'webserv* and G@os:Debian or E@web-dc1-srv.*':
    - match: compound
    - webserver

New in version Beryllium.

Excluding a minion based on its ID is also possible:

salt -C 'not web-dc1-srv'

Versions prior to Beryllium a leading not was not supported in compound matches. Instead, something like the following was required:

salt -C '* and not G@kernel:Darwin'

Excluding a minion based on its ID was also possible:

salt -C '* and not web-dc1-srv'

Precedence Matching

Matches can be grouped together with parentheses to explicitly declare precedence amongst groups.

salt -C '( ms-1 or G@id:ms-3 ) and G@id:ms-3'


Be certain to note that spaces are required between the parentheses and targets. Failing to obey this rule may result in incorrect targeting!

Alternate Delimiters

New in version Beryllium.

Some matchers allow an optional delimiter character specified between the leading matcher character and the @ pattern separator character. This can be essential when the globbing or PCRE pattern may use the default delimiter character :. This avoids incorrect interpretation of the pattern as part of the grain or pillar data structure traversal.

salt -C 'J|@foo|bar|^foo:bar$ or J!@gitrepo!'