It is known that the iteration depth of variables is limited in
Cfengine. As of 3.0.4p2 the following test.cf

body common control
{
    bundlesequence => { "outer", "inner" };
}

bundle agent outer
{
 vars:
    "arr[idx1]" string => "this is an array element";
    "arr[idx2]" slist  => { "This", "is", "an", "array", "element", "too" };

    "choice"    string => "idx2";

 reports:
   Yr2010::
     "outer: $(arr[$(choice)])";
}

bundle agent inner
{
 vars:
     "idx" slist => getindices("outer.arr");

 reports:
   Yr2010::
     "inner: $(outer.arr[$(idx)])";
}

produced the following output:

R: outer: This
R: outer: is
R: outer: an
R: outer: array
R: outer: element
R: outer: too
R: inner: this is an array element
R: inner: $(outer.arr[idx2])

and 3.0.4 wasn't even capable to iterate over an slist in an array in
the outer bundle, so you're using some version earlier than 3.0.4p2, I
guess.

2010/6/7 Daniel Dehennin <daniel.dehen...@baby-gnu.org>:
> Hello,
>
> In the reference manual I found that array can be of type scalar or
> list, but I did not manage to use list iteration:
>
> --8<---------------cut here---------------start------------->8---
> body common control
> {
>    bundlesequence => { "test" };
>    version => "0.0.2";
> }
>
> bundle agent test
> {
>
> vars:
>
>    any::
>
>        "array[key1]" slist => {"val1"};
>        "array[key2]" slist => {"val2.1", "val2.2"};
>        "array[key3]" slist => {"val3"};
>
>        "keys" slist => getindices("array");
>
> commands:
>
>    "/bin/echo $(keys) "
>        args => "$(array[$(keys)])";
> }
> --8<---------------cut here---------------end--------------->8---
>
> Results in:
>
> --8<---------------cut here---------------start------------->8---
> /usr/sbin/cf-agent -K
> Q: ".../bin/echo key1 ": key1 $(array[key1])
> I: Last 1 QUOTEed lines were generated by promiser "/bin/echo key1  
> $(array[key1])"
> I: Made in version '0.0.2' of '/home/dad/.cfagent/inputs/promises.cf' near 
> line 23
> Q: ".../bin/echo key2 ": key2 $(array[key2])
> I: Last 1 QUOTEed lines were generated by promiser "/bin/echo key2  
> $(array[key2])"
> I: Made in version '0.0.2' of '/home/dad/.cfagent/inputs/promises.cf' near 
> line 23
> Q: ".../bin/echo key3 ": key3 $(array[key3])
> I: Last 1 QUOTEed lines were generated by promiser "/bin/echo key3  
> $(array[key3])"
> I: Made in version '0.0.2' of '/home/dad/.cfagent/inputs/promises.cf' near 
> line 23
> --8<---------------cut here---------------end--------------->8---
>
> I found no example, in tutorial, reference manual, solution guide or
> policy starter kit.
>
> Any hints?
>
> Thanks.
> --
> Daniel Dehennin
> Récupérer ma clef GPG:
> gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
>
>



-- 
SY, Seva Gluschenko.
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to