Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergeycherepanov/b110608cb96c8753c62c to your computer and use it in GitHub Desktop.
Save sergeycherepanov/b110608cb96c8753c62c 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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment