Forum: CFEngine Help
Subject: Re: split user passwd array
Author: tuibelgium
Link to topic: https://cfengine.com/forum/read.php?3,24257,24652#msg-24652

I recently picked this up again. I've managed to get this working, but i've 
noticed some strange behaviour.
Below you find an example with 2 bundles. Bundle test2 is a example from the 
reference manual.
Bundel test1 is slighty modified. 
The output of "$(users[$(index)][2])" in test1 is the same as 
"$(users[$(keys_test_2)][2])" in test2.
I'm not able to use "$(users[$(keys_test_1)][2])" because the variable 
$(keys_test_1) is not set or has no value. 

How can it be explained that keys_test_1 gets no value in the test1?

bundle agent test_1
{
vars:
        "pw"     string => "user1:a:1";
        "pw"     string => "user2:b:2";
        "pw"     string => "user3:c:3";
        
        "index" slist   => getindices("pw");
        
        "dim" int => parsestringarray(
                "users",
                "$(pw[$(index)])",
                "\s*#[^\n]*",
                ":",
                "1000",
                "200000"
                );

"keys_test_1" slist => getindices("users");

reports:
  cfengine_3::
        "$(keys_test_1)";
        "$(users[$(index)][2])";
}


bundle agent test_2
{
vars:
        "test_2_array"  string =>
"user1:a:1
user2:b:2
user3:c:3";

        "dim" int => parsestringarray(
                "users",
                "$(test_2_array)",
                "\s*#[^\n]*",
                ":",
                "1000",
                "200000"
                );

        "keys_test_2" slist => getindices("users");

reports:
  cfengine_3::
        "$(keys_test_2)";
        "$(users[$(keys_test_2)][2])";

}


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to