Mercurial > repos > other > Puppet
view modules/stdlib/lib/puppet/parser/functions/getparam.rb @ 0:956e484adc12
Initial public release of Puppet configs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Aug 2014 19:47:38 +0000 |
parents | |
children | c42fb28cff86 |
line wrap: on
line source
# Test whether a given class or definition is defined require 'puppet/parser/functions' 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] if resource[param] end return '' end