Hi,
I already made my top.sls as generic as possible for states.
We assign states in our CMDB and retrieve them with a custom grain.
We end up with a ETNIC_ITOP_STATE custom grain with the list of states to apply to the minion:
ETNIC_ITOP_STATE:
- frontend
My state top.sls looks like this:
base:
# Assigning the roles found in iTop for the minion
{% set ROLES = salt['grains.get']('ETNIC_ITOP_STATE',[]) %}
{% for ROLE in ROLES %}
'G@ETNIC_ITOP_STATE:{{ ROLE }}':
- {{ ROLE }}
{% endfor %}
It works great and we don't have to edit top.sls anymore (which was always a great source of merge conflict before :))
Now I'd like to apply the same kind of logic for pillars top.sls.
Somehow, not all states have pillars named after them (eg: /srv/salt/states/projX/ and /srv/salt/pillars/projX/).
To avoid SLS errors, I should check on master if folder /srv/salt/pillars/projX/ exists for a minion with projX state.
I was thinking of something like this:
base:
{% set ROLES = salt['grains.get']('ETNIC_ITOP_STATE',[]) %}
{% for ROLE in ROLES %}
'G@ETNIC_ITOP_STATE:{{ ROLE }}':
- {% if salt['file.directory_exists']("/srv/salt/pillars/{{ ROLE }}") %}{{ ROLE }}{% else %}No_pillar_named_after_state{% endif %}
{% endfor %}
Obviously, file.directory_exists is executed on the minion so it doesn't work. No_pillar_named_after_state is applied instead of projX.
Is there a way to execute file.directory_exists on the master when compiling top.sls?
Thanks,
Seb