Last active
April 10, 2019 07:08
-
-
Save jfindlay/331a4394281e778a1ae9217edb5728b7 to your computer and use it in GitHub Desktop.
Salt Requisite Tests for `cmd` State
This file contains 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
# The `cmd` state implements its own `onlyif` and `unless` requisites. This sls demonstrates how they are interpreted. | |
{%- if grains['kernel'] == 'Linux' %} | |
echo onlyif true: | |
cmd.run: | |
- onlyif: | |
- '[ "a" = "a" ]' | |
echo onlyif false: | |
cmd.run: | |
- onlyif: | |
- '[ "a" != "a" ]' | |
echo unless true: | |
cmd.run: | |
- unless: | |
- '[ "a" = "a" ]' | |
echo unless false: | |
cmd.run: | |
- unless: | |
- '[ "a" != "a" ]' | |
{%- elif grains['kernel'] == 'Windows' %} | |
echo 'onlyif stderr': | |
cmd.run: | |
- shell: powershell | |
- onlyif: | |
- 'if ("a" -eq "a") { Write-Error "" }' | |
echo 'onlyif not stderr': | |
cmd.run: | |
- shell: powershell | |
- onlyif: | |
- 'if ("a" -ne "a") { Write-Error "" }' | |
echo 'unless stderr': | |
cmd.run: | |
- shell: powershell | |
- unless: | |
- 'if ("a" -eq "a") { Write-Error "" }' | |
echo 'unless not stderr': | |
cmd.run: | |
- shell: powershell | |
- unless: | |
- 'if ("a" -ne "a") { Write-Error "" }' | |
{%- endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Remember: this logic is specific to the
cmd
state and may not apply to others in the same way or at all sincesalt.states.cmd
implements its ownonlyif
andunless
requisites.0
(true
)not 0
(false
)stderr
not stder
onlyif
onlyif
unless
unless
Example