salt.modules.match

The match module allows for match routines to be run and determine target specs

salt.modules.match.compound(tgt, minion_id=None)

Return True if the minion ID matches the given compound target

minion_id

Specify the minion ID to match against the target expression

New in version 2014.7.0.

CLI Example:

salt '*' match.compound 'L@cheese,foo and *'
salt.modules.match.data(tgt)

Return True if the minion matches the given data target

CLI Example:

salt '*' match.data 'spam:eggs'
salt.modules.match.filter_by(lookup, tgt_type='compound', minion_id=None, merge=None, merge_lists=False, default='default')

Return the first match in a dictionary of target patterns

New in version 2014.7.0.

CLI Example:

salt '*' match.filter_by '{foo*: Foo!, bar*: Bar!}' minion_id=bar03

Pillar Example:

# Filter the data for the current minion into a variable:
{% set roles = salt['match.filter_by']({
    'web*': ['app', 'caching'],
    'db*': ['db'],
}, minion_id=grains['id'], default='web*') %}

# Make the filtered data available to Pillar:
roles: {{ roles | yaml() }}
salt.modules.match.glob(tgt, minion_id=None)

Return True if the minion ID matches the given glob target

minion_id

Specify the minion ID to match against the target expression

New in version 2014.7.0.

CLI Example:

salt '*' match.glob '*'
salt.modules.match.grain(tgt, delimiter=':')

Return True if the minion matches the given grain target. The delimiter argument can be used to specify a different delimiter.

CLI Example:

salt '*' match.grain 'os:Ubuntu'
salt '*' match.grain 'ipv6|2001:db8::ff00:42:8329' delimiter='|'
delimiter

Specify an alternate delimiter to use when traversing a nested dict

New in version 2014.7.0.

delim

Specify an alternate delimiter to use when traversing a nested dict

New in version 0.16.4.

Deprecated since version 2015.8.0.

salt.modules.match.grain_pcre(tgt, delimiter=':')

Return True if the minion matches the given grain_pcre target. The delimiter argument can be used to specify a different delimiter.

CLI Example:

salt '*' match.grain_pcre 'os:Fedo.*'
salt '*' match.grain_pcre 'ipv6|2001:.*' delimiter='|'
delimiter

Specify an alternate delimiter to use when traversing a nested dict

New in version 2014.7.0.

delim

Specify an alternate delimiter to use when traversing a nested dict

New in version 0.16.4.

Deprecated since version 2015.8.0.

salt.modules.match.ifelse(*args, tgt_type='compound', minion_id=None, merge=None, merge_lists=False)

New in version 3006.0.

Evaluate each pair of arguments up to the last one as a (matcher, value) tuple, returning value if matched. If none match, returns the last argument.

The ifelse function is like a multi-level if-else statement. It was inspired by CFEngine's ifelse function which in turn was inspired by Oracle's DECODE function. It must have an odd number of arguments (from 1 to N). The last argument is the default value, like the else clause in standard programming languages. Every pair of arguments before the last one are evaluated as a pair. If the first one evaluates true then the second one is returned, as if you had used the first one in a compound match expression. Boolean values can also be used as the first item in a pair, as it will be translated to a match that will always match ("*") or never match ("SALT_IFELSE_MATCH_NOTHING") a target system.

This is essentially another way to express the filter_by functionality in way that's familiar to CFEngine or Oracle users. Consider using filter_by unless this function fits your workflow.

CLI Example:

salt '*' match.ifelse 'foo*' 'Foo!' 'bar*' 'Bar!' minion_id=bar03
salt.modules.match.ipcidr(tgt)

Return True if the minion matches the given ipcidr target

CLI Example:

salt '*' match.ipcidr '192.168.44.0/24'

delimiter Pillar Example:

'172.16.0.0/12':
  - match: ipcidr
  - nodeclass: internal
salt.modules.match.list_(tgt, minion_id=None)

Return True if the minion ID matches the given list target

minion_id

Specify the minion ID to match against the target expression

New in version 2014.7.0.

CLI Example:

salt '*' match.list 'server1,server2'
salt.modules.match.pcre(tgt, minion_id=None)

Return True if the minion ID matches the given pcre target

minion_id

Specify the minion ID to match against the target expression

New in version 2014.7.0.

CLI Example:

salt '*' match.pcre '.*'
salt.modules.match.pillar(tgt, delimiter=':')

Return True if the minion matches the given pillar target. The delimiter argument can be used to specify a different delimiter.

CLI Example:

salt '*' match.pillar 'cheese:foo'
salt '*' match.pillar 'clone_url|https://github.com/saltstack/salt.git' delimiter='|'
delimiter

Specify an alternate delimiter to use when traversing a nested dict

New in version 2014.7.0.

delim

Specify an alternate delimiter to use when traversing a nested dict

New in version 0.16.4.

Deprecated since version 2015.8.0.

salt.modules.match.pillar_pcre(tgt, delimiter=':')

Return True if the minion matches the given pillar_pcre target. The delimiter argument can be used to specify a different delimiter.

CLI Example:

salt '*' match.pillar_pcre 'cheese:(swiss|american)'
salt '*' match.pillar_pcre 'clone_url|https://github\.com/.*\.git' delimiter='|'
delimiter

Specify an alternate delimiter to use when traversing a nested dict

New in version 2014.7.0.

delim

Specify an alternate delimiter to use when traversing a nested dict

New in version 0.16.4.

Deprecated since version 2015.8.0.

salt.modules.match.search_by(lookup, tgt_type='compound', minion_id=None)

Search a dictionary of target strings for matching targets

This is the inverse of match.filter_by and allows matching values instead of matching keys. A minion can be matched by multiple entries.

New in version 2017.7.0.

CLI Example:

salt '*' match.search_by '{web: [node1, node2], db: [node2, node]}'

Pillar Example:

{% set roles = salt.match.search_by({
    'web': ['G@os_family:Debian not nodeX'],
    'db': ['L@node2,node3 and G@datacenter:west'],
    'caching': ['node3', 'node4'],
}) %}

# Make the filtered data available to Pillar:
roles: {{ roles | yaml() }}