On 01/27/2012 10:08 AM, no-re...@cfengine.com wrote:
> Forum: CFEngine Help
> Subject: Re: bundles: can a class argument be passed?
> Author: davidlee
> Link to topic: https://cfengine.com/forum/read.php?3,24675,24680#msg-24680
> 
> Thanks for the responses, which have been helpful.
> 
> Now I think about it, my wish for a 'class' argument is really more like a 
> boolean "something-or-other" that I can use in as class-like selector.   So 
> Todd's example probably provides me with a good way to get going.
> 
> Overall I try to avoid having two bundles which do almost the same thing.  In 
> such a case it is far better design practice to have a single bundle with a 
> controlling argument.
> 
> (My actual application will then go on to call a choice of two further quite 
> different "edit_line" bundles, depending on that incoming argument.)

Here is one that works like that, just play with commenting/uncommenting
the some_class_name expressions in the main bundle.

-- 
Nick Anderson <n...@cmdln.org>
body common control {

bundlesequence => {
"main",
};

inputs => {
"cfengine_stdlib.cf",
};
}

bundle agent main {

classes:
    #"some_class_name" expression => "windows";
    #"some_class_name" expression => "linux";


methods:

some_class_name::
"any" usebundle => test("yes");
!some_class_name::
"any" usebundle => test("no");

}

bundle agent test(class_arg) {
    classes:
        "something_special"  expression => regcmp ("yes", "$(class_arg)");

    vars:
        something_special::
            "var_local" 
                    string => "true", 
                    policy => "free";

        !something_special::
            "var_local" 
                    string => "false",
                    policy => "free";

    reports:
    cfengine::
        "the value of var_local is $(var_local)";

}
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to