Linux – Adding an existing user to a group with puppet

linuxpuppetredhatuser-accountsuser-management

Is it possible to add an existing user to a group with puppet 2.7.18?

We have two modules, each one defines one class :

  • module "user" creates all users, including user foo and user bar.
  • module "subversion" deals with various conf files and creates group svn.

We would like to add user foo to group svn inside module "subversion".

I've tried the membership parameter as described in the existing feature request:

group {
"svn":
    ensure  => present,
    gid     => xxxxx;
}
user {
"foo":
    group      => ["svn"],
    membership => minimum;
}

But I get the following error :

err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Duplicate declaration: User[foo] is already declared in file
/pathto/modules/subversion/manifests/init.pp at line xx; cannot
redeclare at /pathto/modules/users/manifests/init.pp:xxx on node
myserver.example.com

Is this feature is already implemented? If not, is there a good workaround?

Best Answer

If you declare users as virtual resources , you can then use 'realize' or the collection syntax ( User <| ... |>). Here's an example:

@user { 'foo':
  groups     => ['somegroup'],
  membership => minimum,
}

Then realize that virtual user with then collection syntax:

User <| title == foo |>

And elsewhere you can add to the parameters for that virtual resource using plusignment:

User <| title == foo |> { groups +> "svn" }