Created
September 13, 2012 11:51
-
-
Save walkeran/3713826 to your computer and use it in GitHub Desktop.
Exec resource with environment
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
[root@puppet ~]# cd /tmp/puppet/test6 | |
[root@puppet test6]# puppet apply test.pp | |
notice: /Stage[main]//Exec[test2]/returns: executed successfully | |
notice: Finished catalog run in 0.30 seconds | |
[root@puppet test6]# ls | |
output2 test.pp | |
[root@puppet test6]# cat test.pp | |
exec { "test": | |
environment => 'BATCH=myval', | |
path => ['/bin', '/usr/bin'], | |
cwd => '/tmp/puppet/test6', | |
command => 'echo $BATCH > output', | |
unless => 'test "$BATCH" = "myval"' | |
} | |
exec { "test2": | |
environment => 'BATCH=myval2', | |
path => ['/bin', '/usr/bin'], | |
cwd => '/tmp/puppet/test6', | |
command => 'echo $BATCH > output2', | |
unless => 'test "$BATCH" = "thisisnotmyval2"' | |
} | |
[root@puppet test6]# cat output2 | |
myval2 | |
### | |
### Notice, Exec['test'] didn't run because the 'unless' parameter (which compared the env var to the | |
### string I was expecting it to be) prevented it, proving the 'environment' param works with 'unless' | |
### | |
### Also notice, Exec['test2'] did run, re-proving the previous statement, but it also echo'd the env var | |
### correctly into the output2 file, showing that the env var was picked up correctly by the executed command | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment