Forum: CFEngine Help
Subject: Re: edit global list
Author: schattenfell
Link to topic: https://cfengine.com/forum/read.php?3,22770,22840#msg-22840
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.
Yes I already had this solutions with no good results.
In case one (each bundle adds lines into module file) I started with an empty
file for reasons of consistency. So the module file was rewritten for every
CFEngine run, even if there were no changes at all. This was because of the
different file accesses in the different bundles to the same file.
Case two came also in my mind. Because CFEngine don't like "duplicated lines"
in the different templates, I had to use a solution including the commands
section in the bundle agent: "/bin/cat /templates/modules.* > /etc/modules". In
combination with promise_repaired => { "modules_updated" }; for every single
module template, the solution was appropriate.
But my favourite solution would be only using internal slist (maybe also
arrays) in combination with an file update at the end.
So your last idea was really interesting for me as a possible new starting
point. I just tested it with bad news. I seems not to work.
The reason why can be seen in the following simplified example without extra
bundles based on your code:
vars:
"a" int => "1";
"b" int => "1";
"names" slist => { "a", "b" };
"modlists[$(names)]" slist => getindices( "$(names)" );
"modules[$(modlists[$(names)])]" int => "1";
"final_modlist" slist => getindices("modules");
reports:
linux::
"modlists:";
"$(modlists[$(names)])";
"$(modlists)";
"$(modlists)";
"modules:";
"$(modules[$(modlists[$(names)])])";
"final_modlist:";
"$(final_modlist)";
The output is the following:
R: modlists:
R: $(modlists) <-- I would have expecte "R:
loop" like in line 4
R: $(modlists) <-- I would have expecte "R:
drbd" like in line 5
R: loop
R: drbd
R: modules:
R: $(modules[$(modlists)]) <-- I would have expecte R: 1
R: $(modules[$(modlists)]) <-- I would have expecte R: 1
R: final_modlist:
So at the end the final_modlist has no content. CFEngine3 seems not to like the
nested array.
Hints are welcome either solving the nested array problem or finding a better
solution using only list.
Thanks for every reply!
Best wishes
Michael
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine