Skip to content

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

@NdK73

Description

@NdK73

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillarbugbroken, incorrect, or confusing behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions