Reputation:
I am currently getting familiar with salt and wonder how I could re-use the values of pillars in other places (sections) in .sls
files.
In buildout
, I would be able to reference a variable from another section with ${sectionname:varname}
to re-use a once defined value. This is especially handy, when dealing with directories (basedir, appdir). buildout
example:
['foo']
path = /highway/to/hell
['bar']
path = ${foo:path}/lastexit
When I try to reference another variable in an .sls
file, even if it is in the same file, I get always None
. salt
example:
foo:
path: /highway/to/hell
bar:
path: {{ salt['pillar.get']('foo:path') }}/lastexit
salt-ssh minion1 pillar.get bar:path
results in None/lastexit
I have the feeling, that I'm missing something here. Could someone point out, how one does re-use values in salt .sls
Upvotes: 0
Views: 410
Reputation: 93
You can use jinja to assign a value, e.g.:
{% set base_path = salt['pillar.get']('foo:path','/highway/to/hell') %}
foo:
path: {{ base_path }}
bar:
path: {{ base_path }}/lastexit
In this case "/highway/to/hell" is set as a default in case no value is assigned in the pillar or no pillar is found. For more info, see https://docs.saltstack.com/en/latest/topics/jinja/index.html
Upvotes: 0