I am using salt by defining roles which map a list of states to a list of hosts on which to apply the states:
#/srv/pillar/base/top.sls:
{% set h = 'host1, host2,' %}
'L@{{ h }}':
- roles.Servers
{% set h = 'host3, host4,' %}
'L@{{ h }}':
- roles.newServers
#/srv/salt/base/top.sls:
base:
'role:Server': # Mapping a host to a role can be found in: /srv/pillar/top.sls
- match: pillar
- mystate1 # "shared" statefile
- mystate2
'role:newServer':
- match: pillar
- mystate1 # "shared" statefile
- mystate3
Now in a state like mystate1.sls below I want to make a difference what the state does
that should depend on the host list from the role by which the minion was selected.
# /srv/salt/base/mystate1.sls
newPkg:
pkg.installed:
- pkgs:
{% if grains['id'] in roles[ 'Server' ] %} # pseude code: check if 'id' is in hostlist for role 'Server'
- mypackage1 # do this if the current host is in the hostlist of role 'Servers'
{% else %}
- myNewPackage # do that if the host is part of role 'newServers'
{% endif %}
So what I would like to check in the state on the minion for which the state was called is if the minion belongs to the host list of role 'Server' or 'newServer'.
Any idea?