2011-06-21 23:10:33 +02:00
|
|
|
module Puppet::Parser::Functions
|
|
|
|
|
|
|
|
newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
|
|
|
Lookup a variable in a remote namespace.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2011-08-18 00:20:26 +02:00
|
|
|
$foo = getvar('site::data::foo')
|
2011-08-18 00:53:27 +02:00
|
|
|
# Equivalent to $foo = $site::data::foo
|
2011-06-21 23:10:33 +02:00
|
|
|
|
|
|
|
This is useful if the namespace itself is stored in a string:
|
|
|
|
|
2011-08-18 00:53:27 +02:00
|
|
|
$datalocation = 'site::data'
|
2011-08-18 00:20:26 +02:00
|
|
|
$bar = getvar("${datalocation}::bar")
|
2011-08-18 00:53:27 +02:00
|
|
|
# Equivalent to $bar = $site::data::bar
|
2011-06-21 23:10:33 +02:00
|
|
|
ENDHEREDOC
|
|
|
|
|
|
|
|
unless args.length == 1
|
|
|
|
raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
|
|
|
|
end
|
|
|
|
|
2014-07-18 23:36:09 +02:00
|
|
|
begin
|
|
|
|
self.lookupvar("#{args[0]}")
|
|
|
|
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
|
|
|
|
end
|
2011-06-21 23:10:33 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|