Puppet Function: getparam
- Defined in:
- puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb
- Function type:
- Ruby 3.x API
Overview
Takes a resource reference and name of the parameter and returns value of resource's parameter.
Examples:
define example_resource($param) {
}
example_resource { "example_resource_instance":
param => "param_value"
}
getparam(Example_resource["example_resource_instance"], "param")
Would return: param_value
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb', line 4 Puppet::Parser::Functions.newfunction(:getparam, :type => :rvalue, :doc => <<-'ENDOFDOC' Takes a resource reference and name of the parameter and returns value of resource's parameter. *Examples:* define example_resource($param) { } example_resource { "example_resource_instance": param => "param_value" } getparam(Example_resource["example_resource_instance"], "param") Would return: param_value ENDOFDOC ) do |vals| reference, param = vals raise(ArgumentError, 'Must specify a reference') unless reference raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String return '' if param.empty? if resource = findresource(reference.to_s) return resource[param] unless resource[param].nil? end return '' end |