5

A specific case leading to a more general question: I have a salt formula that looks like this:

formula/
    init.sls
    some_other_state.sls
    defaults.yaml

As part of both sls's behavior I want them to load defaults.yaml into a dict. I can do it this way in either of them:

{%- import_yaml formula/defaults.yaml as defaults %}

...but this hardcodes the location of the formula relative to the base of the salt tree, and will break if the tree is ever restructured and the formula moved to (say) a nested directory.

I tried this instead:

{%- import_yaml (slspath + "/defaults.yaml") as defaults %}

This works for init.sls but not for some_other_state.sls; the reason is that slspath expands to the containing directory for the former but the full path for the latter.

What I really want is some equivalent of slspath that always expands to "the directory containing the currently-running sls." I can then specify whatever path I need relative to that.

Does such a variable exist, and if so, what is it?

Andrew
  • 4,058
  • 4
  • 25
  • 37

1 Answers1

4

The variable you are looking for is tpldir which was added in 0c78d7dc.

Clint
  • 101
  • 1
  • 5
  • `tpldir` works in sls and not probably in template as template does not really know what its actual `tpldir` will be. – ring bearer Jul 25 '16 at 12:34