grinferno
grinferno

Reputation: 534

Setting out a list of variables in Salt and then importing into another file

Is it possible to set out a list of salt variables such as:

{% set foo = '1234' %}
{% set bar = '10.1.1.2' %}
{% set environment = salt['grains.get']('env') %}

and then import them into separate .sls file and use them like so:

foo_value = {{ foo }} # sets foo to '1234'
bar_value = {{ bar }} # sets bar to '10.1.1.2'
etc...

Upvotes: 0

Views: 2671

Answers (1)

doz10us
doz10us

Reputation: 777

The best fit should be the import feature. You can store the file with variables as described in question and then import them like:

{% from 'yourfile.jinja' import foo with context %}
{% from 'yourfile.jinja' import bar with context %}
{% from 'yourfile.jinja' import environment with context %}

Or alternatively you can add all of them to an array:

{% set vars = {
  'foo': '1234',
  'bar': '10.1.1.2',
  'environment': salt['grains.get']('env'),
  }
%}

And then import it at once:

{% from 'yourfile.jinja' import vars with context %}

Best practices on using variables (and import) are described at Salt Best Practices page.

Upvotes: 3

Related Questions