On 09/07/2012 11:53 AM, no-re...@cfengine.com wrote:
Forum: CFEngine Help
Subject: Re: Raise a class when class thing1 but not class thing2
Author: neilhwatson
Link to topic: https://cfengine.com/forum/read.php?3,27246,27247#msg-27247
Nick,
Did you check the verbose agent output to see what classes are defined during
the run? I don't think it is possible to undefine a class. So, if thing2 is
defined in a early run it will still be there on later runs.
It is possible to undefine a class, but I am trying to raise a class
(main_cat_test_redfish) when one class (main_cat_test_thing1) is
defined, but another (main_cat_test_thing2) is not defined.
main_cat_test_thing2 should only be defined when cat_tail is true.
main_cat_test_redfish should only be defined when main_cat_test_thing2
is not defined
$ cf-agent -KvIf ./class_when_thing1_but_not_thing2.cf | grep +
cf3> + Private classes augmented:
cf3> + Private classes augmented:
cf3> + main_cat_test_redfish
cf3> + main_cat_test_thing2
cf3> + main_cat_test_thing1
cf3> + Private classes augmented:
cf3> + main_cat_test_redfish
cf3> + main_cat_test_thing2
cf3> + main_cat_test_thing1
cf3> + Private classes augmented:
cf3> + main_cat_test_redfish
cf3> + main_cat_test_thing2
cf3> + main_cat_test_thing1
cf3> + Private classes augmented:
cf3> + Private classes augmented:
R: Hat: true
R: Tail: true
R: I have a cat in a hat with no tail
body common control {
inputs => { "../sketches/CFEngine/stdlib/cfengine_stdlib.cf" };
bundlesequence => { "main" };
}
bundle agent main
{
vars:
"cat_hat" string => "true";
"cat_tail" string => "true";
methods:
"story time" usebundle => test("main.cat_");
}
bundle agent test(prefix)
{
vars:
"bundle" string => "test";
"class_prefix" string => "$(prefix)$(bundle)_";
classes:
"$(class_prefix)thing1" expression => regcmp("true", "$($(prefix)hat)");
"$(class_prefix)thing2" expression => regcmp("true", "$($(prefix)tail)");
# Define redfish when thing one but not thing 2
# Notice that class_prefix contains illegal characters (the dot in main.cat_)
# So when testing the existance of the classes must be careful to
# classify/canonify the strings
"$(class_prefix)redfish" and => { classify("$(class_prefix)thing1"),
classify(not("$(class_prefix)thing2"))
};
reports:
cfengine::
"Hat: $($(prefix)hat)";
"Tail: $($(prefix)tail)";
"I have a cat in a hat with no tail",
ifvarclass => canonify("$(class_prefix)redfish");
}
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine