Currently, if I want to conditionally include an sls file, if the file exists, I need to do some ugly jinja magic:
base:
# For each directory that can have pillar files
{% for root in opts['pillar_roots']['base'] -%}
# Set a variable to the path to check
{% set service_group_sls = '{0}/{1}.sls'.format(root, grains['service_group']) -%}
# Check to see if the file exists, if so, include that pillar file.
{% if salt['file.file_exists'](service_group_sls) %}
'service_group:{{ grains["service_group"] }}':
- match: grain
- {{ grains['service_group'] }}
{% endif %}
{% endfor -%}
What I really want to do is:
base:
'service_group:{{ grains["service_group"] }}':
- match: grain
- ignore_missing: True
- {{ grains['service_group'] }}
I also want to see if a pillar or state sls file exists from the cli, or from inside of a state, for conditional include:
salt-call state.sls_exists mystatssls
salt-call pillar.sls_exists mypillarsls
This way I can call individual states, but only if they actually exist.
Hi @ryan-lane. I think this is a tremendous idea. I really like it. If possible, I'd really like to see this feature included in Lithium. I plan to push for it. :]
Fixed for pillars in #19429
I'm working on something that requires a similar approach and running into an issue that Salt doesn't ignore it if I try to include
a state that does not exist.
It looks like for states the cp.show_states
could come in handy.
The proposed sls_exists
can most likely be a wrapper around that probably?
Too bad this was only implemented for Pillar! Generic support for SLS inclusion in top.sls
(as the title states!) or SLS inclusion from within another SLS would have been epic. But that is no small patch, I'm sure. Thanks @ryan-lane for getting the Pillar part done! :+1:
Yeah... The code for pillar and state top files are separate for some reason, even though they do the exact same thing. I was hoping to do both at the same time, but I only needed pillar and the state top file code looked more difficult to modify. I'm still hoping someone from SaltStackInc will finish this work up :)
Bumping this, as it would really clean up a tedious top.sls in our code.
Linking this to duplicate #20010
+1
I really need this functionality:
include:
- ignore_missing: True
- {{ "servers/%s" % grains.id.replace('.', '_') }}
+1
+1
I tried adding support for it myself a while back, but SaltStack's code is... We'll, let's just say I still have nightmares about it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
Oh no you don't mr.stale-bot. This is still very much needed.
Thank you for updating this issue. It is no longer marked as stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
This feature is still wanted.
Thank you for updating this issue. It is no longer marked as stale.
I could really make use of this feature as well.
I would also like this feature
Most helpful comment
+1
I really need this functionality: