source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/ensure_resources.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 8 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 1.5 KB
Line 
1require 'puppet/parser/functions'
2
3Puppet::Parser::Functions.newfunction(:ensure_resources,
4 :type => :statement,
5 :doc => <<-'ENDOFDOC'
6Takes a resource type, title (only hash), and a list of attributes that describe a
7resource.
8
9 user { 'dan':
10 gid => 'mygroup',
11 ensure => present,
12 }
13
14An hash of resources should be passed in and each will be created with
15the type and parameters specified if it doesn't already exist.
16
17 ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' } , 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
18
19From Hiera Backend:
20
21userlist:
22 dan:
23 gid: 'mygroup'
24 uid: '600'
25 alex:
26 gid: 'mygroup'
27
28Call:
29ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
30
31ENDOFDOC
32) do |vals|
33 type, title, params = vals
34 raise(ArgumentError, 'Must specify a type') unless type
35 raise(ArgumentError, 'Must specify a title') unless title
36 params ||= {}
37
38 if title.is_a?(Hash)
39 resource_hash = Hash(title)
40 resources = resource_hash.keys
41
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])
46 else
47 params_merged = params
48 end
49 function_ensure_resource([ type, resource_name, params_merged ])
50 }
51 else
52 raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash')
53 end
54end
Note: See TracBrowser for help on using the repository browser.