Puppet: Evaluating variables inside onlyif close -


i have variable set @ stage, variable boolean, @ point want exec command based on fact if variable true or false, this:

exec { 'update-to-latest-core':    command     => "do something",   user        => 'root',   refreshonly => true,   path        => [ "/bin/bash", "sbin/" , "/usr/bin/", "/usr/sbin/" ],    onlyif      => 'test ${latest} =      true',   notify      => exec["update-to-latest-database"], } 

so command doesn't work (onlyif => ['test ${latest} = true'],) tried several other ways too, didn't work. simple cannot hard do. can me this, , explain rules behind getting commands execute inside onlyif close. (also cannot use if-close on higher level because have other dependencies )

since $latest puppet variable, not useful defer checking value until catalog applied. technically, in fact, cannot so: puppet interpolate variable's value exec resource's catalog representation, there no variable left time catalog applied, literal.

since resource in question notified resource, must not suppress altogether. if code presented in question not work, because interpolated value of $latest different expect -- example, '1' instead of 'true'. running agent in --debug mode should show details of command being executed.

alternatively, approach different way:

exec { 'update-to-latest-core':    command     => $latest ? { true => "do something", default => '/bin/true' },   user        => 'root',   refreshonly => true,   path        => [ "/bin/bash", "sbin/" , "/usr/bin/", "/usr/sbin/" ],    notify      => exec["update-to-latest-database"], } 

that execute (successfully, , no external effect) whenever $latest false, , run do something command whenever $latest true. choice of command made during catalog building.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -