Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] pillar.file_exists doesn't test directories, and there's no pillar.directory_exists #62158

Open
1 of 6 tasks
NdK73 opened this issue Jun 13, 2022 · 1 comment
Open
1 of 6 tasks
Labels
Bug broken, incorrect, or confusing behavior Pillar
Milestone

Comments

@NdK73
Copy link

NdK73 commented Jun 13, 2022

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
@NdK73 NdK73 added Bug broken, incorrect, or confusing behavior needs-triage labels Jun 13, 2022
@welcome
Copy link

welcome bot commented Jun 13, 2022

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@Ch3LL Ch3LL self-assigned this Jul 21, 2023
@Ch3LL Ch3LL added this to the Argon v3008 milestone Jul 21, 2023
@dwoz dwoz unassigned Ch3LL Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Pillar
Projects
None yet
Development

No branches or pull requests

3 participants