Questions: Is it possible to target minions in top file with negative matching on grains?
Description of Issue/Question
Can I target minions in the top file by applying states if they Do Not have a specific grain? for example, I have a grain called roles and I want to apply specific changes to hosts who have that role and anything else to the rest of the hosts.
base:
'roles:salt-vanguard':
- match:grain
- vanguard-states
'roles:!salt-vanguard':
- match: grain
- all-other-states
The thinking here is I don't want to have to define another role (not-vanguard for example) for every other host who is not in the salt-vanguard group.
Setup
(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).) I have a basic setup with gitfs
Versions Report
Salt Version:
Salt: 2016.3.1
Dependency Versions:
cffi: Not Installed
cherrypy: 3.2.2
dateutil: 1.4.1
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
Jinja2: 2.7.3
libgit2: 0.20.0
libnacl: Not Installed
M2Crypto: 0.20.2
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: 0.20.3
Python: 2.6.6 (r266:84292, May 22 2015, 08:34:51)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.5.0
RAET: Not Installed
smmap: 0.8.1
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: redhat 6.8 Santiago
machine: x86_64
release: 2.6.32-642.1.1.el6.x86_64
system: Linux
version: Red Hat Enterprise Linux Server 6.8 Santiago
@aabognah you could use grain_pcre matching while using a non capturing group. I tested the following example and it works:
base:
'key:(?:(?!val).)*':
- match: grain_pcre
- test-file
That will only run the test-file sls for every minion that does not have the value of val for the grain key. Does this work in your instance?
Here's an example I use of negative pcre matching grains.
base:
'not P@roles:salt-vanguard':
- all-other-states
@Lomexian works perfectly. just needed to add match: compound there. Thanks.