Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add module/function and top.sls syntax to check for sls existence #16687

@ryan-lane

Description

@ryan-lane

Currently, if I want to conditionally include an sls file, if the file exists, I need to do some ugly jinja magic:

base:
  # For each directory that can have pillar files
  {% for root in opts['pillar_roots']['base'] -%}
  # Set a variable to the path to check
  {% set service_group_sls = '{0}/{1}.sls'.format(root, grains['service_group']) -%}
  # Check to see if the file exists, if so, include that pillar file.
  {% if salt['file.file_exists'](service_group_sls) %}
  'service_group:{{ grains["service_group"] }}':
    - match: grain
    - {{ grains['service_group'] }}
  {% endif %}
  {% endfor -%}

What I really want to do is:

base:
  'service_group:{{ grains["service_group"] }}':
    - match: grain
    - ignore_missing: True
    - {{ grains['service_group'] }}

I also want to see if a pillar or state sls file exists from the cli, or from inside of a state, for conditional include:

salt-call state.sls_exists mystatssls
salt-call pillar.sls_exists mypillarsls

This way I can call individual states, but only if they actually exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Featurenew functionality including changes to functionality and code refactors, etc.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions