1 require 'puppet/parser/functions'
3 Puppet::Parser::Functions.newfunction(:ensure_resources,
7 Takes a resource type, title (only hash), and a list of attributes that describe a
11 created resources with the passed type and attributes
13 @example Example usage
20 An hash of resources should be passed in and each will be created with
21 the type and parameters specified if it doesn't already exist.
23 ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' }, 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
35 ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
38 type, title, params = vals
39 raise(ArgumentError, 'Must specify a type') unless type
40 raise(ArgumentError, 'Must specify a title') unless title
43 raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash') unless title.is_a?(Hash)
44 resource_hash = title.dup
45 resources = resource_hash.keys
47 Puppet::Parser::Functions.function(:ensure_resource)
48 resources.each do |resource_name|
49 params_merged = if resource_hash[resource_name]
50 params.merge(resource_hash[resource_name])
54 function_ensure_resource([type, resource_name, params_merged])