On 15 feb 2011, at 09:50, dennis.caboo...@snow.nl wrote:

> Hi there!
> 
> I have a replace_patterns issue.
> 
> - In /tmp/group I have the following:
> 
> root@cfengine:~# grep zenoss /tmp/group
> zenoss:x:1001:
> 
> - I have the following cfengine code:
> 
> ----------
> body common control {
>  bundlesequence => {
>    "test"
>  };
> }
> 
> bundle agent test {
>  files:
>    "/tmp/group11"
>      edit_line => replace_group;
> }
> 
> bundle edit_line replace_group {
>  vars:
>    "group_lines" string => "zenoss:x:1001:user1,user2,user3";
> 
>  replace_patterns:
>    "^zenoss.*$"
>      replace_with => value("$(group_lines)");
> }
> ----------
> 
> - After running cf-agent, /tmp/group looks like this, which is what I want:
> 
> root@cfengine:~# grep zenoss /tmp/group
> zenoss:x:1001:user1,user2,user3
> 
> - Nevertheless there are a lot of errors, which I don't understand. If I
> remove the $ from the end of the pattern, I got the same errors and
> nothing happens:
> 
> 
This pattern will always match and replace the value everytime cfengine runs. I 
had to include cfengine_stdlib.cf else the example does not work. Here is an 
example that i use to edit these kind of files:
body common control {
 inputs => {
        "cfengine_stdlib.cf"
};

 bundlesequence => {
    sara_change_group_users("zenoss","user1,user2,user3")
 };
}

bundle agent sara_change_group_users(group, users)
{
    files:
            "/tmp/group11"
                comment     => "Change group users",
                edit_line   => set_user_field("$(group)","4","$(users)"),
                classes   => if_repaired( group_members_changed );

    reports:
        group_members_changed::
                "Added $(users) to $(group)";
}



--
Bas van der Vlies
b...@sara.nl



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

Reply via email to