puppetlabs-stdlib/lib/puppet/parser/functions/getvar.rb
Jeff McCune 2bca41a9c4 (#8010) Add getvar() rvalue function
This isn't directly related to #8010, but rather indirectly fills the
need to allow the end user to configure where data values are looked up.

This allows the namespace to be passed as a class parameter.  A module
may then quickly and easily look up data from the user-defined
namespace.
2011-06-21 15:12:46 -07:00

23 lines
523 B
Ruby

module Puppet::Parser::Functions
newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
Lookup a variable in a remote namespace.
For example:
$foo = getvar('site::data::foo')
This is useful if the namespace itself is stored in a string:
$bar = getvar("${datalocation}::bar")
ENDHEREDOC
unless args.length == 1
raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
end
self.lookupvar("#{args[0]}")
end
end