Allan Marcus wrote:
> This has probably been discussed, but I would like an exec to only be
> executed if a facter variable is true. Seems there are two ways of
> doing this, but I can only get the "if" way to work.
>
> # $lanl_sav_defdate is a custom fact
> # make sure the live update file is correct, then force a liveupdate
> class forceLiveupdate {
> if $lanl_sav_defdate == 'February13,2008'{
> # execute the live update command
> exec {"liveupdate-now":
> command => "[long command omited]",
> }
> }
> }
That is the easiest way.
> Is this the "right" way of using a conditional, or should I use an
> onlyif? Something like this, which doesn't seem to work for me:
>
> class forceLiveupdate {
> # execute the live update command
> exec {"liveupdate-now":
> command => "[long command omited]",
> onlyif => "match $lanl_sav_defdate == 'February13,2008'",
> }
> }
The 'onlyif' and 'unless' parameters are shell commands, whose exit status
determines if the shell command in the 'command' parameter will be run.
Neither my CentOS, Fedora, Gentoo nor Solaris machines have a command named
'match', so that would return non-zero, and your command will not be run.
A working version would rather use
onlyif => "[ '$lanl_sav_defdate' = 'February13,2008' ]"
However, there are several problems with this. First of all, you will have
worse performance, since it will involve a fork() and exec(), which aren't
the cheapest things one can do. Second, you have quoting problems; if your
lanl_sav_defdate happens to contain a single quote, you will have problems.
(In the upcoming 0.25 there is a function 'shellquote()' which can help you
with that.)
On the other hand, if you have requires or subscribes elsewhere that points
to Exec[liveupdate-now], then those won't work if you wrap the exec in an
if statement.
/Bellman
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---