Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ryan-lane/67f1d66cef7a0d6d5cef to your computer and use it in GitHub Desktop.
Save ryan-lane/67f1d66cef7a0d6d5cef to your computer and use it in GitHub Desktop.
Using an environment variable in a state file
MYENVVAR="world" salt-call state.template test.sls
Create a file with contents from an environment variable:
file.managed:
- name: /tmp/hello
- contents: {{ salt['environ.get']('MYENVVAR') }}
{% set myenvvar = salt['environ.get']('MYENVVAR') %}
{% if myenvvar %}
Create a file with contents from an environment variable:
file.managed:
- name: /tmp/hello
- contents: {{ salt['environ.get']('MYENVVAR') }}
{% else %}
Fail - no environment passed in:
test:
- fail_without_changes
{% endif %}
@blarghmatey
Copy link

This approach won't work in 2014.1.x and before. To do this in older releases you can do
{{ salt['cmd.run']('echo $MYENVVAR') }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment