1 # Test whether a given class or definition is defined
2 require 'puppet/parser/functions'
4 Puppet::Parser::Functions.newfunction(:getparam,
8 Returns the value of a resource's parameter.
11 value of a resource's parameter.
13 Takes a resource reference and name of the parameter and
14 returns value of resource's parameter. Note that user defined
15 resource types are evaluated lazily.
17 @example Example Usage:
19 # define a resource type with a parameter
20 define example_resource($param) {
23 # declare an instance of that type
24 example_resource { "example_resource_instance":
25 param => "'the value we are getting in this example''"
28 # Because of order of evaluation, a second definition is needed
29 # that will be evaluated after the first resource has been declared
31 define example_get_param {
32 # This will notice the value of the parameter
33 notice(getparam(Example_resource["example_resource_instance"], "param"))
36 # Declare an instance of the second resource type - this will call notice
37 example_get_param { 'show_notify': }
39 Would notice: 'the value we are getting in this example'
41 > **Note** that since Puppet 4.0.0 it is possible to get a parameter value by using its data type
42 and the [ ] operator. The example below is equivalent to a call to getparam():
43 ```Example_resource['example_resource_instance']['param']``
47 reference, param = vals
48 raise(ArgumentError, 'Must specify a reference') unless reference
49 raise(ArgumentError, 'Must specify name of a parameter') unless param && param.instance_of?(String)
51 return '' if param.empty?
53 resource = findresource(reference.to_s)
55 return resource[param] unless resource[param].nil?