1

I'm having trouble using regex with salt to target every minion except one.

I have tried every example I can find and exhausted my limited understanding of Perl regex. I expect this to target every minion (all named something.domain.co.uk):

^(?!.*mail).*$

However it returns zero values.

Any help would be greatly appreciated

7
  • Your requirement is not very clear to me... Any examples of things you want to match and things you don't want to match?
    – Jerry
    Apr 13 '14 at 17:07
  • Sorry Jerry, I want to match everything except mail.domain.co.uk. The other servers are web.domain.co.uk, edi.domain.co.uk, forum.domain.co.uk, etc. Apr 13 '14 at 17:14
  • Okay, are you using the -E option?
    – Jerry
    Apr 13 '14 at 17:17
  • I was unaware of an -E option. Running "salt -E '^(?!.*mail).*$' test.ping" does return the correct minions. But I need this in the top.sls file, can I include -E there? Apr 13 '14 at 17:23
  • 1
    You can put an answer with everything that was needed. It's fine to answer your own question :)
    – Jerry
    Apr 13 '14 at 18:34
0

In your top.sls, use the following syntax to match:

base:
  '^(?!.*mail).*$':
    - match: pcre
    - states_to_apply

Source: http://docs.saltstack.com/en/latest/topics/targeting/globbing.html

0

PCRE Minion_ID Compound Matcher denoted by E@ is what you want.

When targeting minions on the command line:

salt -C 'E@^(foo|bar)$' test.ping

Or in a top file:

base:
  'E@^(?!.*mail).*$':
    - match: compound

Yes, you can use salt -E 'regex' or - match: pcre and skip the leading E@ for pure minion_id regex, but chaining multiple matchers (grains PCRE, cidr ip block, etc) can be quite expressive:

 salt -C 'G@os:(Ubuntu|Debian) and G@domain:example\.(com|net) and E@^(?!.*mail).*$'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.