Forum: CFEngine Help
Subject: Re: multidimensional array usage
Author: lauwersw
Link to topic: https://cfengine.com/forum/read.php?3,23753,24069#msg-24069
Hi,
I think I have found a variant of this bug. Using this code:
bundle agent level1
{
methods:
any::
"a" usebundle => level2("passwd");
}
bundle agent level2(file)
{
vars:
any::
"count" int => readstringarray("paramarray", "/etc/$(file)", "\s*#[^\n]*",
":", 100, 10000);
"param" slist => getindices("paramarray");
"value[$(param)]" string => "$(paramarray[$(param)][1])";
reports:
cfengine::
"file $(file)";
"count $(count)";
"param $(param)";
"value $(paramarray[6])";
}
I get the following output:
cf3> =========================================================
cf3> reports in bundle level2 (1)
cf3> =========================================================
cf3>
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: file passwd
cf3> .........................................................
cf3>
cf3> Report: file passwd
cf3> R: file passwd
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: count 30
cf3> .........................................................
cf3>
cf3> Report: count 30
cf3> R: count 30
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: value /bin/bash
cf3> .........................................................
cf3>
cf3> Report: value /bin/bash
cf3> R: value /bin/bash
I'm definitely missing the expansion of $(param) here. However if I change the
readstringarray function to use the full filename instead of the file variable,
it works as I would expect:
cf3> =========================================================
cf3> reports in bundle level2 (1)
cf3> =========================================================
cf3>
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: file passwd
cf3> .........................................................
cf3>
cf3> Report: file passwd
cf3> R: file passwd
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: count 30
cf3> .........................................................
cf3>
cf3> Report: count 30
cf3> R: count 30
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: param root
cf3> .........................................................
cf3>
cf3> Report: param root
cf3> R: param root
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: param rpcuser
cf3> .........................................................
cf3>
cf3> Report: param rpcuser
cf3> R: param rpcuser
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: param gopher
cf3> .........................................................
cf3>
cf3> Report: param gopher
cf3> R: param gopher
etc...
I can also make it work by defining an interim bundle, and then referring to
the variable as $(interim.file). As you guys already found, the array is
populated correctly as you can directly reference elements from it, it's just
the slist creation that somehow fails.
So am I doing anything wrong? Or does this warrant a new bug report or
supplementing the existing one from Victor?
Thanks!
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine