FAQ
Hi all,

I want to add/source a Pillar SLS only if it exists. Currently my Pillar
top.sls looks like this:


{% set host = salt['grains.get']('host') %}

base:
[...]

   'host:{{ host }}':
     - match: grain
     - hosts.{{ host }}


But this throws an error if there is no such file. How can I load the
file only if it exists? Is that even possible or is this another way to
accomplish something similar?

Thanks, Shorty

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Sebastien Wains at Aug 20, 2014 at 9:58 am
    Have you tried

    {% set host = salt['grains.get']('host') | default(None) %}



    On Wednesday, August 20, 2014 11:17:25 AM UTC+2, Markus Shorty Uckelmann
    wrote:
    Hi all,

    I want to add/source a Pillar SLS only if it exists. Currently my Pillar
    top.sls looks like this:


    {% set host = salt['grains.get']('host') %}

    base:
    [...]

    'host:{{ host }}':
    - match: grain
    - hosts.{{ host }}


    But this throws an error if there is no such file. How can I load the
    file only if it exists? Is that even possible or is this another way to
    accomplish something similar?

    Thanks, Shorty
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Markus \"Shorty\" Uckelmann at Aug 20, 2014 at 10:25 am

    On 20.08.2014 11:58, Sebastien Wains wrote:
    Have you tried

    {% set host = salt['grains.get']('host') | default(None) %}
    The "host" Grains is one of the default Grains which is always there.
    So this would never default to "None". And Pillar would still try to
    load the file "host.{{ host }}" even if it's not there.

    Peace, Shorty

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jason Godden at Aug 20, 2014 at 11:07 am

    On 20/08/14 20:25, Markus "Shorty" Uckelmann wrote:
    On 20.08.2014 11:58, Sebastien Wains wrote:
    Have you tried

    {% set host = salt['grains.get']('host') | default(None) %}
    The "host" Grains is one of the default Grains which is always there.
    So this would never default to "None". And Pillar would still try to
    load the file "host.{{ host }}" even if it's not there.

    Peace, Shorty
    I do something like this in init.sls for my host pillar. You could adapt
    this for the pillar top file as well I believe.

    {% include 'hosts/config/' + grains['slsid'] + '.sls' ignore missing %}

    This is the only line in my init.sls file from there I include per host
    SLS files. My "slsid" grain is a 'safe' representation of the host ID
    with the "." character replaced with underscores (dedicated grains
    function). I'm sure there are other ways to do this but this quick hack
    worked for me.

    J

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Markus \"Shorty\" Uckelmann at Aug 20, 2014 at 11:58 am
    On 20.08.2014 13:07, Jason Godden wrote:

    Hi Jason,
    I do something like this in init.sls for my host pillar. You could
    adapt this for the pillar top file as well I believe.

    {% include 'hosts/config/' + grains['slsid'] + '.sls' ignore
    missing %}
    I got this working, but not in the top.sls. What I did was this:

    in top.sls:

    base:
       [...]
       '*':
         - hosts.host

    and in hosts/host.sls:

    {% include 'hosts/' + salt['grains.get']('host') + '.sls' ignore
    missing %}

    That seems to do the trick.

    Thanks a lot, Shorty

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ethan Erchinger at Aug 20, 2014 at 9:45 pm
    A very similar question was asked a couple weeks ago, you can use something
    like:

    {% if salt['file.file_exists')('hosts/{0}.sls'.format(grains.host)) %}
    '{{ id }}':
       - hosts.{{ grains.host }}
    {% endif %}

    This works because Pillar is rendered on the master, so it's a local file.

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedAug 20, '14 at 9:17a
activeAug 20, '14 at 9:45p
posts6
users4

People

Translate

site design / logo © 2022 Grokbase