Last active
May 24, 2022 06:52
-
-
Save ryan-lane/67f1d66cef7a0d6d5cef to your computer and use it in GitHub Desktop.
Using an environment variable in a state file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MYENVVAR="world" salt-call state.template test.sls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a file with contents from an environment variable: | |
file.managed: | |
- name: /tmp/hello | |
- contents: {{ salt['environ.get']('MYENVVAR') }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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
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') }}