Created
October 28, 2011 08:20
-
-
Save alvagante/1321861 to your computer and use it in GitHub Desktop.
Puppet add_arguments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Parser::Functions::newfunction(:add_arguments, :doc => <<-'ENDHEREDOC') do |args| | |
Converts a hash into a set of arguments that are added to the specified resource. | |
This function takes two arguments: a resource name, and a hash describing | |
a set of resources. The hash should be in the form `{title => {parameters} }`: | |
# A hash of arguments: | |
$myarguments = { | |
uid => '1330', | |
group => allstaff, | |
groups => ['developers', 'operations', 'release'], | |
} | |
add_arguments(User["al"], $myarguments) | |
ENDHEREDOC | |
raise ArgumentError, ("add_arguments(): wrong number of arguments (#{args.length}; must be 2)") if args.length != 2 | |
resource_name = args[0] | |
args[1].each do |title, params| | |
raise ArgumentError, 'params should not contain title' if(params['title']) | |
p_resource = Puppet::Parser::Resource.new(resource_name) | |
# p_resource = Puppet::Parser::Resource.new(type_name, title, :scope => self, :source => resource) | |
params.merge(:name => title).each do |k,v| | |
p_resource.set_parameter(k,v) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://github.com/puppetlabs/puppet/blob/master/lib/puppet/parser/functions/create_resources.rb