Forum: CFEngine Help
Subject: Re: edit global list
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,22770,22788#msg-22788
You can't apparently modify a variable outisde of your bundle's context. There
are two ways to do this which immediately pop to mind, though.
One way is to have each individual bundle add its own lines into the module
file. Perhaps they directly add lines to a single file, or perhaps they each
edit individula per-bundle files located under a directory, and then a final
assembly bundle reads ll teh per-bundle files and merges them together. The
second approach there is more expensive in terms of resources, as you do
slightly more disk I/O - but you get the benefit of having a bit of an audit
log showing which parts of the file came from which module. You could acheive
the same benefit by bracketing each module's "section" in the file with a
start- and end-marker (which would allow each bundle to "own" a piece of the
file, emptying its section and then inserting lines as needed). The brackets
would, most likely, be comments like "start $(this.bundle)" or similar.
The other possibility would be for each bundle to define a list within itself,
using the same name. Then you'd have a final assembly bundle which finds all
of the bundles' lists, and assembles them. Without testing the code, I'd guess
something somewhat like this:
bundle agent build_file {
vars:
"bundle_names" slist => { "a", "b" };
methods:
"part" usebundle => "subassembly_$(bundle_names)";
"whole" usebundle => "assemble";
}
bundle agent subassembly_a {
vars:
NEEDS_WHATEVER:: "modules" int => 1;
}
bundle agent subassembly_a {
vars:
NEEDS_SOMETHING:: "modules" int => 1;
}
bundle agent assemble {
vars:
"names" slist => { @(build_file.bundle_names) };
"modlists[$(names)]" slist => getindices( "$(names).modules" );
"modules[$(modlists[$(names)])]" int => 1;
"final_modlist" slist => getindices( "modules" );
}
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine