Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative includes for pillar #8875

Closed
pniederw opened this issue Nov 28, 2013 · 25 comments · Fixed by #56851
Closed

Support relative includes for pillar #8875

pniederw opened this issue Nov 28, 2013 · 25 comments · Fixed by #56851
Labels
Core relates to code central or existential to Salt Feature new functionality including changes to functionality and code refactors, etc. Pillar ZRelease-Sodium retired label
Milestone

Comments

@pniederw
Copy link

The dot notation that's supported for relative includes in state files (include: - .other) doesn't seem to work for pillar. Would be just as useful there.

@basepi
Copy link
Contributor

basepi commented Dec 2, 2013

Sounds reasonable to me. Thanks for the request!

@arnisoph
Copy link
Contributor

+1

2 similar comments
@craig5
Copy link
Contributor

craig5 commented Sep 16, 2014

+1

@pykler
Copy link
Contributor

pykler commented Nov 25, 2014

+1

@eliasp
Copy link
Contributor

eliasp commented Dec 23, 2014

It seems to be broken in general. See also #14497.
I wonder whether the breakage of relative includes in pillars is caused by the same bug.

@basepi
Copy link
Contributor

basepi commented Dec 23, 2014

Very possible, thanks for tagging these together @eliasp.

@wuxxin
Copy link
Contributor

wuxxin commented Jan 26, 2015

+1
because this way you can write pillar state files that are identical, and just edit common.sls (in the same subdir), to change some values


something/common.sls
{% load_yaml as common %}
test:
   whatever: true
   another:
      hu: he
{% endload %}

something/another.sls

include:
  - .common

{{ common.something }}

@uvsmtid
Copy link
Contributor

uvsmtid commented Apr 3, 2015

To complement this issue, this is how to live now with workaround which I personally use extensively.

Workaround

Push a variable with location of the pillar into the pillar template being included using defaults as described in doc how to include pillar.

Example

The top file is not used, but it's important to note that it cannot use include directly.

All we need to do is to list the first "entry point" pillar which will include others.

# top.sls
base:
    '*':
        - main

Include pillar and tell it where it is located using this_pillar.

# main.sls
include:
    - deep.inside.directory.structure.pillar_a:
        defaults:
            this_pillar: deep.inside.directory.structure.pillar_a

Include other pillars relatively:

# deep.inside.directory.structure.pillar_a.sls
include:
    - {{ this_pillar }}.whatever:
    - {{ this_pillar }}.blah_blah_blah:
    - {{ this_pillar }}.last_one:

Proper complication

Because you don't know (or you don't want to keep this in mind) whether any pillar subsequently includes relatively anything else or not, the safest way is to pass this_pillar recursively to every other one being included (just in case).

# deep.inside.directory.structure.pillar_a.sls
include:
    - {{ this_pillar }}.whatever:
        defaults:
            this_pillar: {{ this_pillar }}.whatever
    - {{ this_pillar }}.blah_blah_blah:
        defaults:
            this_pillar: {{ this_pillar }}.blah_blah_blah
    - {{ this_pillar }}.last_one:
        defaults:
            this_pillar: {{ this_pillar }}.last_one

or wrapped in a loop:

# deep.inside.directory.structure.pillar_a.sls
include:
    {% for sub_item in [ 'whatever', 'blah_blah_blah', 'last_one ] %}
    - {{ this_pillar }}.{{ sub_item }}:
        defaults:
            this_pillar: {{ this_pillar }}.{{ sub_item }}
    {% endfor%}

Conclusion

It's ugly, but it works.

@titilambert
Copy link
Contributor

+1

5 similar comments
@enver
Copy link

enver commented Nov 4, 2015

+1

@adithep
Copy link

adithep commented Nov 20, 2015

+1

@peter-slovak
Copy link
Contributor

+1

@damon-atkins
Copy link
Contributor

+1

@mlalpho
Copy link
Contributor

mlalpho commented Apr 7, 2016

+1

@damon-atkins
Copy link
Contributor

+1

@damon-atkins
Copy link
Contributor

@meggiebot please add Labels Core & Pillar if appropriate.

@Ch3LL Ch3LL added Pillar Core relates to code central or existential to Salt labels Oct 3, 2016
@ealphonse
Copy link

Hi, it is also the case when one - require: - sls: a sls in a salt file.

@mallniya
Copy link

+1
shockingly sudden it's not implemented yet

@nomoo
Copy link

nomoo commented Oct 24, 2017

+1

@SuperTux88
Copy link

There is a 👍 functionality in GitHub nowadays ... there is no need to +1 anymore, because it only create unneeded notifications, thanks.

@danlsgiga
Copy link
Contributor

Just hit this very same issue too. Will change my formulas to use the absolute path instead of relative.
Would be helpful if the Pillar docs had a note letting people know that pillar requires absolute paths for template imports.

@damon-atkins
Copy link
Contributor

@Ch3LL can this request be escalated into the up coming release its such a large difference between states and pillars.

@Ch3LL
Copy link
Contributor

Ch3LL commented Aug 20, 2018

ping @saltstack/team-core anyone have interest in tackling this one?

@damon-atkins
Copy link
Contributor

The following is support in states however not supported in pillar

include:
  - .common

Lets keep this on the radar if you want this in pillars, please thumbs up the original comment/description
Issues Sorted by Top Thumbs Up

@clallen
Copy link
Contributor

clallen commented Sep 13, 2018

+1

@dwoz dwoz closed this as completed in 8342898 Mar 12, 2019
waynew added a commit to waynew/salt that referenced this issue Apr 22, 2020
Allow pillar relative includes

Fixes saltstack#8875 and Fixes saltstack#56186
@waynew waynew mentioned this issue Apr 22, 2020
3 tasks
joechainz pushed a commit to joechainz/salt that referenced this issue Apr 22, 2020
Fixes saltstack#8875 - a longstanding issue
@sagetherage sagetherage added the ZRelease-Sodium retired label label May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core relates to code central or existential to Salt Feature new functionality including changes to functionality and code refactors, etc. Pillar ZRelease-Sodium retired label
Projects
None yet
Development

Successfully merging a pull request may close this issue.