1 require 'puppet/parser/functions'
3 Puppet::Parser::Functions.newfunction(:ensure_resources,
6 Takes a resource type, title (only hash), and a list of attributes that describe a
14 An hash of resources should be passed in and each will be created with
15 the type and parameters specified if it doesn't already exist.
17 ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' } , 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
29 ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
32 type, title, params = vals
33 raise(ArgumentError, 'Must specify a type') unless type
34 raise(ArgumentError, 'Must specify a title') unless title
37 raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash') unless title.is_a?(Hash)
38 resource_hash = title.dup
39 resources = resource_hash.keys
41 Puppet::Parser::Functions.function(:ensure_resource)
42 resources.each do |resource_name|
43 params_merged = if resource_hash[resource_name]
44 params.merge(resource_hash[resource_name])
48 function_ensure_resource([type, resource_name, params_merged])