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

Skip to content

Include State only if it exists #20010

@puneetk

Description

@puneetk

Hi,
I would like to be able to include an sls file only if it exists. The use case for this came up when working with Collectd saltstack formula pillar, and the way the formula is setup. What i would like to do is include the collectd formula in my top.sls file and then use the pillar to configure what states get included from the formula.

For eg the collectd/init.sls file would look like

include:
  - collectd.package
  - collectd.service
  {% for state in salt['pillar.get']('collectd:plugins:enabled') %}
  - collectd.{{state}}
  {% endfor %} 

And the corresponding pillar would be

collectd:
  FQDNLookup: true
  TypesDB: ['/usr/share/collectd/types.db']
  plugins: 
    enabled: [battery, cpu, entropy, load, memory, swap, users, write_graphite ]

Now this would require that we have states for each plugin that is enabled. Instead if i could do the following, I can now make extra configs for the plugins, if needed and include the one file in the top.sls by enabling the collectd plugin in a pillar.

include:
  - collectd.package
  - collectd.service
include_if_exists:
  {% for state in salt['pillar.get']('collectd:plugins:enabled') %}
  - collectd.{{state}}
  {% endfor %} 

Currently i would have to make two pillars and then iterate over them separately.

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