Puppet Class: accounts

Defined in:
manifests/init.pp

Overview

Class: accounts

Uses accounts::hiera to create users.

Parameters:

$groups

Array of groups that should be present.

$users

Array of users that should be present.

$user_uids

A hash table connecting usernames with their uids.

$user_info

A hash table with user information.

Todo:

  • TODO: Grab nested hiera (defined in multiple yaml definitions).

Parameters:

  • groups (Any) (defaults to: hiera_array('accounts::groups', []))
  • users (Any) (defaults to: hiera_array('accounts::users', []))
  • user_uids (Any) (defaults to: hiera_hash('accounts::user_uids', {}))
  • user_info (Any) (defaults to: hiera_hash('accounts::user_info', {}))
  • user_defaults (Any) (defaults to: hiera('accounts::user_defaults', {}))
  • purge (Any) (defaults to: hiera('accounts::purge', false))


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'manifests/init.pp', line 20

class accounts (
  $groups        = hiera_array('accounts::groups', []),
  $users         = hiera_array('accounts::users', []),
  $user_uids     = hiera_hash('accounts::user_uids', {}),
  $user_info     = hiera_hash('accounts::user_info', {}),
  $user_defaults = hiera('accounts::user_defaults', {}),
  $purge         = hiera('accounts::purge', false)
) {

  if $::puppetversion =~ /^3/ {
    ## Since this is puppet 3, the values above have been initialized but without array/hash support.. redo!
    $_groups    = hiera_array('accounts::groups', [])
    $_users     = hiera_array('accounts::users', [])
    $_user_uids = hiera_hash('accounts::user_uids', {})
    $_user_info = hiera_hash('accounts::user_info', {})
  } else {
    $_groups    = $groups
    $_users     = $users
    $_user_uids = $user_uids
    $_user_info = $user_info
  }

  group {$groups:
    ensure => 'present',
  }

  $create_users = select_users($_users, $_user_uids, $_user_info, $user_defaults)
  create_resources('accounts::hiera', $create_users)

  if $purge {
  ## Gets all users that have a uid configured.
  $all_users = hash_keys($_user_uids)
  ## Get the users that are not in the users array.
  $users_absent = array_substract($all_users, $_users)
  ## Create a big hash containing user information (but then absent...)
  $absent_users = select_users($users_absent, $_user_uids, {}, {'ensure' => 'absent'})
  create_resources('accounts::hiera', $absent_users)
  }

}