I’m trying to define a variable if it matches a class.  The below code doesn’t 
work.

$ cat test.cf

body common control
{
        bundlesequence  =>      { testit };
}
bundle agent testit
{
vars:
        class_to_test_on::
                "testfile"      string  =>      "/var/tmp/testfile";
                "test_list"     slist   =>      { 
readstringlist("$(testfile)","#[^\n]*","[\n]",99999999,99999999) };
classes:
        "class_to_test_on"      expression      =>      
strcmp("cfengine","cfengine");
reports:
        class_to_test_on::
                "contents of test_list was $(test_list)";
}



Classes are interpreted by Cfengine after variables.

$ /var/cfengine/bin/cf-agent -I -K -f /var/tmp/test.cf
R: contents of test_list was $(test_list)


If I comment out the class from the variable definition, it works.

$ /var/cfengine/bin/cf-agent -I -K -f /var/tmp/test.cf
R: contents of test_list was cfengine is the best product ever!
R: contents of test_list was i just wish i could force classes to be defined 
before variables


My solution to this problem is to define a class in global scope, and then 
execute a method: usebundle statement to dive down in scope.  I then define 
variables in that lower scope based off the global class.  This kind of sucks.  
Is there a better work around?
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to