Hi,

I'm running cfengine 3.0.5p1 I would like to add a line to the /etc/passwd
file.  However, the file has a netgroup entry at the end so I would like to
insert the line directly before it.

I have an /etc/passwd file that ends like this:
    ..
    blah:x:1000:1000::/home/blah:/bin/bash
    +...@hostname:x:::::

I would like it to look like this when I'm done:
    ..
    blah:x:1000:1000::/home/blah:/bin/bash
    testuser:x:1001:1001::/home/testuser:/bin/bash
    +...@hostname:x:::::


I tried adapting one of the methods in the standard library:

bundle agent users {
    vars:
        "user_array[testuser]" string =>
"testuser:x:1001:1001::/home/testuser:/bin/bash";
    files:
        "/etc/passwd"
            edit_line => append_before_netgroup(users.user_array),
            create => "false",
            perms => mog("0644", "root", "root");

}

bundle edit_line append_before_netgroup(v) {
    vars:
        "index"        slist => getindices("$(v)");
    classes:
        "add_$(index)" not => userexists("$(index)");
    insert_lines:
        "$($(v)[$(index)])",
            ifvarclass => "add_$(index)",
            location => "before_netgroup";
}

body location before_negroup {
    select_line_match => "^[+].*",
    before_after => "before";
}

This does not work.  It always appends the testuser entry to the end of the
file.  I've tried changing the regex to match the line in different ways,
I've changed the regex to match other lines in the file, and I've tried
using select_region.  None of them seem to work.  Is there something that
I'm just doing wrong, or is this a bug? And, if I am doing something wrong
could someone kindly point out my mistake?

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

Reply via email to