Having this structure in /srv/salt/pillar/servers.sls
servers:
# Monitors
- m1:
- roles: [ monitor ]
- ips: [ 192.168.0.1 ]
- b2:
- roles: [ monitor ]
- ips: [ 192.168.0.2 ]
# BPs
- w2:
- roles:
- webserver:
- type: [ apache ]
- ips: [ 192.168.0.3 ]
I want to use that information in my top.sls file.
How can I select for instance the servers that have the monitor role? Or the servers that have type apache?
base:
'*':
- common
{% Filter the servers that have the rol monitor %}
- mon
{% endfor %}
{% Filter the servers that have the type apache %}
- web_apache
{% endfor %}
According to the documentation, this works:
# Any minion for which the pillar key 'somekey' is set and has a value
# of that key matching 'abc' will have the 'xyz.sls' state applied.
'somekey:abc':
- match: pillar
- xyz
...but I don't think it suits your use case. Your "roles" item is a list, and I'm guessing you want something more like "if any item in that list is "monitor", apply state X. That won't work this way.
I'm pretty sure your approach is flawed. Instead of using a pillar file to map servers to roles and from there to states, just do it directly in top:
base:
'*':
- common
'm*':
- mon
'w*':
- web_apache
That's top's intended purpose, after all. If your minion IDs don't fit nicely into globs, look into nodegroups as an alternative.