On Fri, Dec 02, 2011 at 03:02:33PM -0500, no-re...@cfengine.com wrote: >Forum: CFEngine Help >Subject: Re: controlling redhat-style startup services via chkconfig >Author: matt_garman >Link to topic: https://cfengine.com/forum/read.php?3,24162,24165#msg-24165 > >And also, for what it's worth, if I do away with the "variable" list >declaration, it works as expected. "check_service_enabled.cf": > >bundle agent check_service_enabled >{ > vars: > # need_ntp:: "service" slist => { "ntpd", "named" }; > # !need_ntp:: "service" slist => { "named" }; > "service" slist => { "ntpd", "named" }; > > methods: > redhat|centos|SuSE:: > "any" usebundle => rh_chkconfig_status(${service}); > > reports: > need_ntp:: "need NTP"; > !need_ntp:: "do NOT need NTP"; >} > > >When run, prints this: > >R: service ntpd is enabled >R: service named is enabled >R: need NTP > > >The above is what I expect, but I'd like to do it conditionally, based on the >"need_ntp" class I defined.
You can't do this (easily) because vars: promises are processed before classes: promises. Thus, but the time you have defined the "needs_ntp" class, it's too late--you've already processed the vars: definitions. You have at least two possible workarounds: 1) use hard classes in vars:. This works because hard classes are defined before the processing of the promises. 2) do some trickery with isvariable() when defining classes to create what I call a "guard" class, then use that to define a variable in the next pass through the bundle. It's complicated and ugly. -- Jesse Becker NHGRI Linux support (Digicon Contractor) _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine