I think I get it: ifvarclass does not build or make or set any class, it USES the class expression specified in the value of ifvarclass, and it uses it by ANDing it with the normal class expression.
Best, Aleksey On Thu, Sep 15, 2011 at 4:49 PM, Nicolas Charles <nicolas.char...@normation.com> wrote: > No, what it says that you can use both the class expression and the > ifvarclass to conditionnaly execute a promise, and you can use variable > in the ifvarclass, that CFEngine will expand and match against an > existing class name > So it doesn't build a class, it checks if a class has the name (hence > the name of the attribute : ifvarclass) > > Regards > Nicolas > > Le 14/09/2011 14:08, Aleksey Tsalolikhin a écrit : >> Thank you, Seva. The reference manual states ifvarclass builds out a >> class from variable content: >> >> CFEngine 3 has a new class predicate ifvarclass which is ANDed with >> the normal class expression, and which is evaluated together with the >> promise. It may contain variables as long as the resulting expansion >> is a legal class expression. >> >> Best, >> Aleksey >> >> >> On Wed, Sep 14, 2011 at 12:34 AM, Seva Gluschenko >> <seva.glusche...@gmail.com> wrote: >>> Aleksey, >>> >>> Don't misguide newcomers ) The ifvarclass attribute does NOT create a >>> class from variable, it allows to build out a class name from a >>> variable content and check whether such class has been defined already >>> or not. To create (i.e. to define) a class from a variable, one must >>> use classes: section. >>> >>> 2011/9/14 Aleksey Tsalolikhin <atsaloli.t...@gmail.com>: >>>> Hi, Jerome. I suggest using cf-promises to check the syntax on your >>>> policy: >>>> >>>> [cfengine00 ~]# cf-promises -f ./test.cf >>>> Arguments to function readfile(.) do not tally. Expect 2 not 1 >>>> Promise (version not specified) belongs to bundle 'g' in file >>>> './test.cf' near line 5 >>>> [cfengine00 ~]# >>>> >>>> You have to tell readfile max number of bytes to read from the file. >>>> >>>> >>>> If you want to explicitly make a class (rather than just use >>>> ifvarclass to create >>>> the class), you can do it with a classes type promise as Seva suggested. >>>> >>>> {{{ >>>> >>>> bundle common g >>>> { >>>> vars: >>>> >>>> "temp" string => readfile( "/tmp/test.txt", "99" ); >>>> >>>> classes: >>>> "$(temp)" expression => "any"; >>>> } >>>> >>>> bundle agent animal >>>> { >>>> commands: >>>> "/bin/echo $(g.temp)" >>>> ifvarclass => >>>> canonify("$(g.temp)"); >>>> reports: >>>> DOG:: >>>> "I have a pet dog."; >>>> } >>>> >>>> }}} >>>> >>>> How's that? >>>> >>>> Aleksey >>>> >>>> >>>> On Tue, Sep 13, 2011 at 11:36 AM, Jerome Yanga <jya...@esri.com> wrote: >>>>> Aleksey, >>>>> >>>>> I came up with the following but I seem to be misinterpreting the >>>>> reference manual. I have also used canonify to no avail. Help. >>>>> >>>>> $ cat /tmp/test.txt >>>>> DOG >>>>> >>>>> bundle common g >>>>> { >>>>> vars: >>>>> >>>>> "temp" string => readfile( "/tmp/test.txt" ); >>>>> } >>>>> >>>>> bundle agent animal >>>>> { >>>>> commands: >>>>> "/bin/echo $(g.temp)" >>>>> ifvarclass => "$(g.temp)"; >>>>> reports: >>>>> DOG:: >>>>> "I have a pet dog."; >>>>> } >>>>> >>>>> Regards, >>>>> j >>>>> >>>>> -----Original Message----- >>>>> From: Aleksey Tsalolikhin [mailto:atsaloli.t...@gmail.com] >>>>> Sent: Tuesday, September 13, 2011 11:20 AM >>>>> To: Jerome Yanga >>>>> Cc: help-cfengine@cfengine.org >>>>> Subject: Re: CFEngine Help: how to convert vars to a class >>>>> >>>>> Yes, you can do it using the ifvarclass, which converts a variable to >>>>> a class. Could you please read the ifvarclass section of the >>>>> reference manual, and let me know if you have any questions. >>>>> >>>>> Best, >>>>> Aleksey >>>>> >>>>> >>>>> On Tue, Sep 13, 2011 at 11:13 AM, Jerome Yanga <jya...@esri.com> wrote: >>>>>> Is it possible to do what I am attempting to? >>>>>> >>>>>> Regards, >>>>>> j >>>>>> >>>>>> -----Original Message----- >>>>>> From: Jerome Yanga >>>>>> Sent: Monday, September 12, 2011 4:27 PM >>>>>> To: 'Aleksey Tsalolikhin' >>>>>> Cc: 'help-cfengine@cfengine.org' >>>>>> Subject: RE: CFEngine Help: how to convert vars to a class >>>>>> >>>>>> Aleksey, >>>>>> >>>>>> Thank you for the quick response. >>>>>> >>>>>> My main objective is to make the contents of /tmp/test.txt into a class. >>>>>> Hence, I would like to do the reporting. >>>>>> >>>>>> bundle agent animal >>>>>> { >>>>>> reports: >>>>>> DOG:: >>>>>> "I have a pet dog."; >>>>>> } >>>>>> >>>>>> Regards, >>>>>> j >>>>>> >>>>>> -----Original Message----- >>>>>> From: Aleksey Tsalolikhin [mailto:atsaloli.t...@gmail.com] >>>>>> Sent: Monday, September 12, 2011 4:15 PM >>>>>> To: Jerome Yanga >>>>>> Cc: help-cfengine@cfengine.org >>>>>> Subject: Re: CFEngine Help: how to convert vars to a class >>>>>> >>>>>> On Mon, Sep 12, 2011 at 3:58 PM, Jerome Yanga <jya...@esri.com> wrote: >>>>>>> I saw another post on how to do this but it does not seem to work for >>>>>>> me. Please correct my syntax >>>>>> How's this? >>>>>> >>>>>> [cfengine00 ~]# cat /tmp/test.txt >>>>>> DOG >>>>>> [cfengine00 ~]# cat test.cf >>>>>> body common control { >>>>>> bundlesequence => { "animal" }; >>>>>> } >>>>>> >>>>>> bundle common g >>>>>> { >>>>>> vars: >>>>>> >>>>>> "temp" string => readfile("/tmp/test.txt", "4" ); >>>>>> } >>>>>> >>>>>> bundle agent animal >>>>>> { >>>>>> commands: "/bin/echo $(g.temp)"; >>>>>> commands: >>>>>> "/bin/echo I have a pet dog." >>>>>> ifvarclass => "$(g.temp)"; >>>>>> } >>>>>> [cfengine00 ~]# cf-agent -f ./test.cf >>>>>> Q: ".../bin/echo DOG": DOG >>>>>> I: Last 1 quoted lines were generated by promiser "/bin/echo DOG" >>>>>> [cfengine00 ~]# >>>>>> >>>>>> Note the use of ifvarclass attribute to use a variable as a class; and >>>>>> the full name of the variable (including the bundle name) in g.temp. >>>>>> CFEngine bundles have scope, so you have to use the full name to call >>>>>> a variable from another bundle (even a global variable). >>>>>> >>>>>> Yours, >>>>>> -at >>>>>> >>>>>> >>>>> >>>> _______________________________________________ >>>> Help-cfengine mailing list >>>> Help-cfengine@cfengine.org >>>> https://cfengine.org/mailman/listinfo/help-cfengine >>>> >>> >>> >>> -- >>> SY, Seva Gluschenko. >>> >> _______________________________________________ >> Help-cfengine mailing list >> Help-cfengine@cfengine.org >> https://cfengine.org/mailman/listinfo/help-cfengine > > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine > _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine