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]", } } } 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''", } } --- Thanks, Allan Marcus 505-667-5666 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Thomas Bellman wrote:> 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.There is an easy workaround for the last problem: define an exec with /bin/true in the else-branch: | exec { "liveupdate-now": | command => "/bin/true # fake", | } This allows one to ignore wether or not the exec is "active". Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Aug 25, 2009 at 9:00 AM, David Schmitt<david@dasz.at> wrote:> > Thomas Bellman wrote: >> 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. > > There is an easy workaround for the last problem: define an exec with > /bin/true in the else-branch: > > | exec { "liveupdate-now": > | command => "/bin/true # fake", > | } > > This allows one to ignore wether or not the exec is "active".I''ve done this like this in the past: exec { "my_command": command => $some_variable ? { "true" => "blah blah some real command", "false" => "/bin/true", } } but it always feels hacky. -- Nigel Kersten nigelk@google.com System Administrator Google, Inc. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Ahhh! Ok, I get it now. Thanks for all the advice. --- Thanks, Allan Marcus 505-667-5666 On Aug 25, 2009, at 8:39 AM, 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]", > } > } > } > > 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''", > } > } > > > --- > Thanks, > > Allan Marcus > 505-667-5666 > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---