salt: Entry in pillar top.sls with dot in path does not work

Hey folks,

with the version 0.14.0 it does not work to have a dot in a dirname which servers a pillar.

Example: As a top.sls in /srv/pillar

base: 
    '*' 
      - data
      - dir.with.dot.in.dirname

With a pillar tree structure as follows: /srv/pillar/ /srv/pillar/top.sls /srv/pillar/data/init.sls /srv/pillar/dir.with.dot.in.dirname/init.sls

Issuing $ salt-call pillar.data --local will complain, that dir.with.dot.in.dirname was not found.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 1
  • Comments: 39 (25 by maintainers)

Commits related to this issue

Most upvoted comments

And then, this was easier than I expected: 3. Using an ext_pillar, in particular PillarStack, with:

## /etc/salt/master

...
ext_pillar:
  - stack:
    - /srv/pillar/stack.cfg
...

and:

## /srv/pillar/stack.cfg

hosts/{{ minion_id }}.sls

and again eg:

## /srv/pillar/hosts/foo.example.com.sls

foo: bar
baz: whee

This is what I’m leaning toward for my situation; this also has the added benefit of being able to reference these when setting normal other/pillar values (eg with ext_pillar_first: true).

I was wanting to do this today (store host-specific data in fqdn-named files). In case it’s valuable to anyone else coming here from a google search, as I did, I found these two approaches useful:

  1. Leveraging @st0ne-dot-at’s post above and going with the aforementioned _ separator:

    ## /srv/pillar/top.sls:
    
    {% set under_id = grains['id'].replace(".","_") %}
    
    base:
      '*':
        - hosts/{{ under_id }}
    

    and eg:

    ## /srv/pillar/hosts/foo_example_com.sls
    
    foo: bar
    baz: whee
    

    Of course, other separators could be used (, = + etc). I tried several and couldn’t find any that substituted well enough for . to go with.

  2. Leveraging https://github.com/saltstack/salt/issues/23910#issuecomment-120371039, with:

    ## /srv/pillar/top.sls:
    
    base:
      '*':
        - fqdn
    

    and:

    ## /srv/pillar/fqdn.sls
    
    {% include "hosts/" + grains['id'] + ".sls" %}
    

    and eg:

    ## /srv/pillar/hosts/foo.example.com.sls
    
    foo: bar
    baz: whee
    

I’m using the following workaround for fqdn specific pillar data:

The node specific file for server www.example.com is: /etc/salt/pillar/servers/com/example/www.sls ( = reversed fqdn )

/etc/salt/pillar/top.sls:

base:
  '*':
    - servers

/etc/salt/pillar/servers/init.sls:

{% set rfqdn = '.'.join(grains['fqdn'].lower().split('.')|reverse) %}
include:
  - servers.{{ rfqdn }}

/etc/salt/pillar/servers/com/example/www.sls:

what:
  ever:
    specific:
      data: query