Forum: CFEngine Help Subject: Re: user management darwin / looping over 2dimensional array? Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,26204,26453#msg-26453
Bernhard, Unfortunately this is a known issue - list expansion beyond one-level arrays is iffy when using variable indices - your "foo" example works fine because it has fixed indices. The best workaround for this that I can think of is to store the slist elements as comma-separated strings, and split them using splitstring(), as shown in this example: body common control { bundlesequence => { "test" }; } bundle agent test { vars: # Instead of "foo" slist => { "hey", "there" }; "foo" string => "hey,there"; "foo" string => "bar two"; # Instead of "foo" slist => { "good", "bye" }; "foo" string => "good,bye"; "foo" string => "baz two"; methods: "any" usebundle => foo("test.foo"); } bundle agent foo(info) { vars: "foos" slist => getindices("$(info)"); reports: # We print the "two" elements here, and delegate the "one" elements # to the foo_one bundle through the methods: call cfengine:: "$(info)[$(foos)]: $($(info)[$(foos)])"; methods: "any" usebundle => foo_one("$(foos)", "$(info)"); } bundle agent foo_one(name, info) { vars: "ones" slist => splitstring("$($(info)[$(name)])", ",", "9999"); reports: cfengine:: "$(info)[$(name)]: $(ones)"; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine