Target minions using roles defined in pillar

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Target minions using roles defined in pillar



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 %}




1 Answer
1



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS