[BUG] pillar.file_exists doesn't test directories, and there's no pillar.directory_exists
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
calling
{% if salt['pillar.file_exists']('test') %}
always fails. Just changing it to
{% if salt['pillar.file_exists']('test/init.sls') %}
works as expected (as long as test/init.sls is there, even if empty).
Setup
From /srv/pillar:
- top.sls (working version):
{% set dom=grains['domain']|replace('.', '_') %}
{% set hostbase = "{0}_{1}".format(grains['host'], dom) %}
base:
'*':
- default
{% if salt['pillar.file_exists']('hostdata/'+hostbase+'.sls') %}
- hostdata.{{hostbase}}
{% endif %}
{% if salt['pillar.file_exists'](dom+'/init.sls') %}
'*.{{ grains['domain'] }}':
- {{ dom }} # init.sls contains the domain defaults
{% if salt['pillar.file_exists']("{0}/{1}".format(dom,grains['host'])+'.sls') %}
- {{ dom }}.{{ grains['host'] }} # Host-specific pillars
{% endif %}
{% endif %}
- hostdata/host_domain_name_tld.sls : generic pillar data for host
- domain_name_tld/ : pillar data for hosts in domain.name.tld
- domain_name_tld/host.sls : pillar data for host.domain.name.tld
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify) kvm
- VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
Steps to Reproduce the behavior
salt '*' saltutil.refresh_pillar && salt ctl\* pillar.items
does not show items in domain_name_tld/host.sls since the first if fails when testing the directory. If, like in the snippet above, I test for init.sls, it works as expected.
Expected behavior
pillar.file_exists should treat a directory like a file and return true if it exists. Alternatively, there should be a pillar.directory_exists function (and a notice in the docs, maybe).
Versions Report
salt --versions-report
Salt Version:
Salt: 3004.1
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.8.1
docker-py: Not Installed
gitdb: 4.0.5
gitpython: 3.1.14
Jinja2: 2.11.3
libgit2: 1.1.0
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.0
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: 3.9.7
pygit2: 1.4.0
Python: 3.9.2 (default, Feb 28 2021, 17:03:44)
python-gnupg: Not Installed
PyYAML: 5.3.1
PyZMQ: 20.0.0
smmap: 4.0.0
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: debian 11 bullseye
locale: utf-8
machine: x86_64
release: 5.10.0-14-amd64
system: Linux
version: Debian GNU/Linux 11 bullseye
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the pillar.file_exists entry point and reproduce the reported behavior using the provided top.sls layout, checking both an existing directory and a file path. Determine whether the expected behavior is directory recognition or a separate directory_exists API; done means the selected behavior works for the pillar layout and is documented or covered by verification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100