Forum: Cfengine Help
Subject: Re: set_user_field multiple lines
Author: regan99
Link to topic: https://cfengine.com/forum/read.php?3,21094,21176#msg-21176
Was your goal for it to look like this?
backoffice:x:1002:user1,user2,user3
exploration:x:1003:user4,user5
If so, I think it's the same issue someone was having in the user management
bundle. It is iterating through the whole group_lines list before actually
setting the value in your /tmp/group file. That's why only the last value in
the group_lines list is seen.
To make it iterate over everything, sort of simulating a foreach loop, I think
you need to do an associative array. Maybe something like this:
vars:
"groups" slist => { "group1", "group2" };
"array" string => "user1,user2,user3";
"array" string => "user4,user5";
Then, to actually change the /tmp/group file, do this:
edit_line => set_user_field("$(groups)", 4, "$(array[$(groups)])");
I think the $(array[$(groups)])" will actually map the list of users you want
to each group the way you want (if I understand your goal). Take this with a
grain of salt though, I am a newb with cfengine. :)
I made the following file to test this out:
body common control
{
bundlesequence => { "example" };
}
bundle agent example
{
vars:
"groups" slist => { "group1", "group2" };
"array" string => "user1,user2,user3";
"array" string => "user4,user5";
reports:
cfengine_3::
"$(groups) has these members: $(array[$(groups)])";
}
When I ran it, these were the results:
R: group1 has these members: user1,user2,user3
R: group2 has these members: user4,user5
So, it does what I think. But what I think may not be what you are asking!
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine