Puppet Function: select_users

Defined in:
lib/puppet/parser/functions/select_users.rb
Function type:
Ruby 3.x API

Overview

select_users()Any

This function creates a hashtable containing all defined users combined with the user uids and user information.

Arguments:

users         - array or string
user_uids     - hash mapping users to uids
user_info     - hash mapping users to additional information (keys, password, homedir, ...)
user_defaults - hash which will be used as default parameters for each created user.

Returns:

  • (Any)


3
4
5
6
7
8
9
10
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
40
41
# File 'lib/puppet/parser/functions/select_users.rb', line 3

newfunction(
  :select_users,
  :type => :rvalue,
  :doc => <<-EODOC
    This function creates a hashtable containing all defined users combined
    with the user uids and user information.

    Arguments:
      users         - array or string
      user_uids     - hash mapping users to uids
      user_info     - hash mapping users to additional information (keys, password, homedir, ...)
      user_defaults - hash which will be used as default parameters for each created user.
  EODOC
) do |args|
  raise Puppet::ParseError, "select_users(): requires 3 or 4 arguments, got #{args.length}" unless [3,4].include?(args.length)
  users     = args.shift
  user_uids = args.shift
   = args.shift
  user_defaults = args.shift || {}

  raise Puppet::ParseError, "select_users(): first argument (users) is not an array or string." unless (users.is_a?(Array) or users.is_a?(String))
  raise Puppet::ParseError, "select_users(): second argument (user_uids) is not a hash." unless user_uids.is_a?(Hash)
  raise Puppet::ParseError, "select_users(): third argument (user_info) is not a hash." unless .is_a?(Hash)
  raise Puppet::ParseError, "select_users(): fourth argument (user_defaults) is not a hash." unless user_defaults.is_a?(Hash)


  hash = {}
  [users].flatten.each do |user|
    function_warning(["select_users(): User '#{user}' has ensure set in user_info. This will override the value in user_defaults."]) if [user] and [user].keys.include?('ensure')
    raise Puppet::ParseError, "select_users(): User '#{user}' is not found in user_uids." unless user_uids.keys.include?(user)

    hash[user] = {}
    hash[user]['uid'] = user_uids[user]
    hash[user].merge!([user]) if .keys.include?(user)
    hash[user].merge!(user_defaults)
  end
  hash

end