Forum: CFEngine Help Subject: Re: CFEngine Help: Re: bundle common variables Author: sauer Link to topic: https://cfengine.com/forum/read.php?3,25444,25457#msg-25457
Nick Anderson Wrote: ------------------------------------------------------- > On 04/03/2012 10:52 AM, Denis Zinevich wrote: > > btw, one more clarification about bundle common > > > > do i have to include my common bundles to > > body common control bundlesequence ? > > They will either have to be in the bundlesequence > or you will need to call them with a methods type promise. To clarify (or muddy): variables defined in included files exist even if the actual bundles they're in are not in the bundlesequence or ever otherwise executed. Same deal with classes defined in common bundles. The exception is that variables and classes used in the common control body need to be defined directly in promises.cf; they can't be in included files at all, because the file inclusion happens after common control has been processed. But anyway, the vars-are-defined-without-the-bundle-being-"run" thing has an interesting side effect. If you have a variable or class which executes a program (via execresult() or similar), that program gets run both by cf-promises (possibly three times) and by cf-agent (again, probably three times) even if you take the containing bundle out of the bundlesequence. Further, if you do that in a common bundle, the program gets run by all binaries when they reevaluate the policy - including cf-execd, cf-serverd, and cf-monitord. root@host:/tmp # cat include.cf body common control { inputs => { "otherinclude.cf" }; bundlesequence => { "a" }; } bundle common a { reports: cfengine:: "Imported variable is $(otherbundle.othervar)"; } root@host:/tmp # cat otherinclude.cf bundle agent otherbundle { vars: "othervar" string => execresult("/bin/echo hello", "noshell"); } root@host:/tmp # cf-agent -Kf ./include.cf R: Imported variable is hello cf-serverd example, changing the command to touch: root@host:/tmp # cat otherinclude.cf bundle agent otherbundle { vars: "othervar" string => execresult("/bin/touch /tmp/file", "noshell"); } root@host:/tmp # rm /tmp/file root@host:/tmp # cf-serverd -f ./include.cf Could not bind server address !!! System error for bind: "Address already in use" Could not bind server address !!! System error for bind: "Address already in use" Couldn't open bind an open socket root@host:/tmp # ls /tmp/file /tmp/file And even cf-promises: root@host:/tmp # rm /tmp/file root@host:/tmp # cf-promises -f ./include.cf root@host:/tmp # ls /tmp/file /tmp/file Neat, eh? It makes sense, but is something to be aware of. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine