A collection of task oriented solutions in Puppet

 

Create a group

Challenge

You want to create a group.

Solution

class add_group {

  # minimum required.
  group { 'logusers':
    ensure => 'present',
  }

  # create a group with a specific GID.
  group { 'stats':
    gid => 2001,
  }

}

Explanation

Creating a new group via puppet only requires the resource to be named and that ensure => 'present' be specified. If you specify a GID (Group ID) then you can even skip the ensure, otherwise you must provide it; and the new groups GID will be chosen by your operating system.

If you specify a different GID on a group that already exists puppet will change the GID in /etc/group but will not change the ownership of any existing files and directories.

By default most Linux distributions will use the groupadd provider, which doesn't allow you to manage group members, so you'll have to do it on the user resources instead.