Is it possible to use Jinja to render a Salt state file, based on the salt environment?
Here's a simple example of setting a timezone for a server. I want to set the timezone to New York if we are in the 'dev' environment, otherwise the timezone should be set to London.
timezone.sls
{% if saltenv == 'dev' %}
America/New_York
{% else %}
Europe/London
{% endif %}
timezone.system
Executing salt '*' state.sls timezone saltenv='dev' gives the error:
Rendering SLS "base:timezone" failed: Jinja variable 'saltenv' is undefined; line 1
EDIT - as requested, here's the contents of the 'top.sls' file:
base:
'*':
- basic
- git
If anyone is still looking for an answer to this:
{% set saltenv = salt.config.get('saltenv') %}
{% if saltenv == 'dev' %}
America/New_York
{% else %}
Europe/London
{% endif %}
timezone.system
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With