Forum: CFEngine Help
Subject: Supplementing an array within a bundle
Author: davidlee
Link to topic: https://cfengine.com/forum/read.php?3,23923,23923#msg-23923
(cfengine community 3.1.4; RHEL 5.6)
I'm wanting to do something very similar to COPBL's "set_variable_values",
where one bundle calls another, via "usebundle" with an associative-array
argument. The main significant difference is that within the destination
bundle I want to supplement that array with some additional items before using
it. Indeed, that destination bundle will itself then use "edit_line" with
"set_variable_values" (but for the moment, I'm simply trying to debug this with
a "reports").
So something like:
bundle agent caller
{
vars:
"v" string => "outer-value-1";
"v" string => "outer-value-2";
methods:
any::
"any" usebundle => dest("caller.v");
}
bundle agent dest(v)
{
vars:
"$(v)" string => "default-1";
"$(v)" string => "default-2";
"index" slist => getindices("$(v)");
reports:
my_machine::
"index: $(index) value: $($(v)[$(index)])";
}
What I would expect from the above is four lines of output:
R: index: caller1 value: outer-value-1
R: index: caller2 value: outer-value-2
R: index: dest1 value: default-1
R: index: dest2 value: default-2
But what I actually get is just the "caller*" lines; the "dest*" lines are not
there. it is as though the supplementing hasn't happened.
Now I realise that what I'm asking is for the inner (dest) bundle to change an
array belonging to the outer (caller) bundle. The documentation seems silent
on whether or not this is allowed. So I also tried expanding the inner (dest)
bundle to copy the associative array into a local one, then to supplement and
use that local one ("attrs" below), thus:
vars:
"index" slist => getindices("$(v)");
"attrs[$(index)]" string => "$($(v)[$(index)])";
"attrs" string => "default-1";
"attrs" string => "default-2";
"index_attrs" slist => getindices("attrs");
reports:
my_machine::
"index: $(index_attrs) value: $(attrs[$(index_attrs)])";
But that gives me the opposite result: I only get the "dest*" lines, not the
"caller*" lines.
Has anyone got a known-working example of such a principle at work? (As a say,
ultimately the inner (dest) bundle is going to do an "edit_line" using the
COPBL "set_variable_values" with this cumulative array.)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine