Forum: CFEngine Help Subject: Re: conditional setting of a variable Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,23180,23182#msg-23182
David, ifvarclass indeed does not work inside the vars: section (I agree this would be nice), but you can use the traditional class-expression blocks to conditionally define variables, like in this example: body common control { bundlesequence => { "test" }; } bundle agent test { classes: "runtime_condition" expression => fileexists("/tmp/foo"); vars: "foo" string => "bar"; runtime_condition:: "conditional" string => "this sometimes happens"; reports: cfengine_3:: "foo: $(foo)"; "conditional: $(conditional)"; } When running it: $ /var/cfengine/bin/cf-agent.exe -KI -f ./test_variables_classes.cf R: foo: bar R: conditional: $(conditional) $ touch /tmp/foo $ /var/cfengine/bin/cf-agent.exe -KI -f ./test_variables_classes.cf R: foo: bar R: conditional: this sometimes happens _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine