Check for pillar file's existence?
I don't think there's a way to check if a pillar file exists using just Jinja. This would be useful to have per-node pillar override files that can be conditionally included, since trying to include a non-existent pillar results in an error.
External pillars are the closest workaround.
This does sound reasonable. Thanks for the request!
This seems to for me
Setting a pillar: pillar_key: pillar_value
Checking if pillar is defined in a state file {% if pillar['pillar_key'] is defined %}
@hazaelsan can you validate for you use case?
Apologies for the ludicrous delay :/
http://grokbase.com/t/gg/salt-users/148m57601n/pillars-conditionally-add-pillar-file-in-top-sls is pretty much the same scenario, the workaround listed there is:
{% if salt['file.file_exists')('hosts/{0}.sls'.format(grains.host)) %}
'{{ id }}':
- hosts.{{ grains.host }}
{% endif %}
I'd love to see a proper solution that doesn't suffer a race condition though :)
It would still be nice to have this without the previously mentioned workarounds or using ext_pillars like pepa or something.
+1 for this.
+1
+1
I've spent quite some time developing something based on the workaround that @hazaelsan mentioned a few years ago but is compatible with git_pillar . This seems to work for us:
{%- set curpath = opts.pillar_roots[saltenv] %}
{%- for gitfsremote in curpath %}
{%- if salt['file.file_exists']('{0}/hosts/{1}.sls'.format(gitfsremote, opts.id)) or
salt['file.file_exists']('{0}/hosts/{1}/init.sls'.format(gitfsremote, opts.id)) %}
- hosts.{{ opts.id }}
{%- endif %}
{%- endfor %}
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.
Features shouldn't get marked as stale, stalebot.
Thank you for updating this issue. It is no longer marked as stale.
This would be a useful feature. I attempted cp.list_master with_pillar=True prefix=foo, but it doesn't include the pillar files - and file.file_exists only works in a masterless setup if the pillar is queried from the correct base directory.
@hazaelsan Closing this due to age, the old version of Salt and Python 2. Can you retest this with the latest release of Salt 3006.2 and if still an issue, please open a new issue, which will have metrics in tracking issues.