salt icon indicating copy to clipboard operation
salt copied to clipboard

Check for pillar file's existence?

Open hazaelsan opened this issue 12 years ago • 13 comments

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.

hazaelsan avatar Jul 20 '14 04:07 hazaelsan

This does sound reasonable. Thanks for the request!

basepi avatar Jul 21 '14 17:07 basepi

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?

wongster80 avatar Aug 18 '15 09:08 wongster80

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 :)

hazaelsan avatar Oct 17 '15 16:10 hazaelsan

It would still be nice to have this without the previously mentioned workarounds or using ext_pillars like pepa or something.

llua avatar Oct 16 '16 04:10 llua

+1 for this.

hnagri avatar Nov 17 '16 05:11 hnagri

+1

paul-mulvihill avatar Dec 13 '16 16:12 paul-mulvihill

+1

aabognah avatar Jan 31 '17 18:01 aabognah

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

RPDiep avatar Jun 22 '18 10:06 RPDiep

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.

stale[bot] avatar Jan 10 '20 12:01 stale[bot]

Features shouldn't get marked as stale, stalebot.

darkpixel avatar Jan 10 '20 16:01 darkpixel

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 10 '20 16:01 stale[bot]

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.

tacerus avatar Dec 26 '22 12:12 tacerus

@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.

dmurphy18 avatar Aug 30 '23 20:08 dmurphy18