#
module Puppet::Parser::Functions
newfunction(:getvar, :type => :rvalue, :doc => <<-'DOC') do |args|
- Lookup a variable in a given namespace.
- Returns undef if variable does not exist.
+ @summary
+ Lookup a variable in a given namespace.
- For example:
+ @return
+ undef - if variable does not exist
- $foo = getvar('site::data::foo')
- # Equivalent to $foo = $site::data::foo
+ @example Example usage
+ $foo = getvar('site::data::foo') # Equivalent to $foo = $site::data::foo
- This is useful if the namespace itself is stored in a string:
+ @example Where namespace is stored in a string
+ $datalocation = 'site::data'
+ $bar = getvar("${datalocation}::bar") # Equivalent to $bar = $site::data::bar
- $datalocation = 'site::data'
- $bar = getvar("${datalocation}::bar")
- # Equivalent to $bar = $site::data::bar
-
- Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
+ > **Note:** from Puppet 6.0.0, the compatible function with the same name in Puppet core
will be used instead of this function. The new function also has support for
digging into a structured value. See the built-in
[`getvar`](https://puppet.com/docs/puppet/latest/function.html#getvar) function