Forum: CFEngine Help
Subject: Re: add users to /etc/shadow
Author: bbomgardner
Link to topic: https://cfengine.com/forum/read.php?3,22920,22949#msg-22949

If you want to modify the password after the line is already there this will 
require a field edit.  What is common to do use a bundle that does both, 
depending on what is found in the file:

1. Insert line if not present
2. Field change if line is present

This is what the set_variable_values bundle does.

Try testing with this sample (the bundles if_ok and col are in the cfengine 
standard lib):


body common control {
bundlesequence => { "test" };
}

bundle agent test {
files:

 "/tmp/shadow"
   create       =>   "true",
   edit_line    =>   set_shadow_values("user1","foo");
}

bundle edit_line set_shadow_values(user,pw) {
field_edits:

  "^$(user):.*"

     edit_field => col(":","2","$(pw)","set"),
        classes => if_ok("$(user)_line_ok");

insert_lines:

  "$(user):$(pw):::::::",
      ifvarclass => "!$(user)_line_ok";
}

body classes if_ok(x)
{
promise_repaired => { "$(x)" };
promise_kept => { "$(x)" };
}

body edit_field col(split,col,newval,method)
{
field_separator    => "$(split)";
select_field       => "$(col)";
value_separator    => ",";
field_value        => "$(newval)";
field_operation    => "$(method)";
extend_fields      => "true";
allow_blank_fields => "true";
}


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

Reply via email to