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