Defined Type: admin::groupmembers

Defined in:
modules/admin/manifests/groupmembers.pp

Overview

Parameters:

  • default_member (String) (defaults to: 'root')


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'modules/admin/manifests/groupmembers.pp', line 11

define admin::groupmembers(
    String $default_member = 'root',
) {


    $gdata = $::admin::data['groups'][$name]
    $group_name = pick($gdata['posix_name'], $name)
    $members = Array($gdata['members'], true)
    $system_members = Array($gdata['system_members'], true)

    $user_list = ($members + $system_members).filter |$user| { $user =~ NotUndef }
    $joined_user_list = $user_list.empty ? {
        true    => $default_member,
        default => $user_list.join(','),
    }


    # this list is inclusive.  anyone not defined is removed.
    # check for group existence and if so compare current users
    $group_nonexistent="getent group ${group_name} | xargs test -z"
    $members_match="getent group ${group_name} | cut -d ':' -f 4 | grep -E ^${joined_user_list}$"
    exec { "${group_name}_ensure_members":
        command   => "/usr/bin/gpasswd ${group_name} -M ${joined_user_list}",
        path      => '/usr/bin:/bin',
        unless    => "${group_nonexistent} || ${members_match}",
        logoutput => true,
        require   => User[$user_list],
    }
}