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'})
33 type, title, params = vals
34 raise(ArgumentError, 'Must specify a type') unless type
35 raise(ArgumentError, 'Must specify a title') unless title
39 resource_hash = title.dup
40 resources = resource_hash.keys
42 Puppet::Parser::Functions.function(:ensure_resource)
43 resources.each { |resource_name|
44 if resource_hash[resource_name]
45 params_merged = params.merge(resource_hash[resource_name])
47 params_merged = params
49 function_ensure_resource([ type, resource_name, params_merged ])
52 raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash')