Last change
on this file since 30960 was 30960, checked in by davidb, 8 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
938 bytes
|
Line | |
---|
1 | module Puppet::Parser::Functions
|
---|
2 |
|
---|
3 | newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
---|
4 | Lookup a variable in a remote namespace.
|
---|
5 |
|
---|
6 | For example:
|
---|
7 |
|
---|
8 | $foo = getvar('site::data::foo')
|
---|
9 | # Equivalent to $foo = $site::data::foo
|
---|
10 |
|
---|
11 | This is useful if the namespace itself is stored in a string:
|
---|
12 |
|
---|
13 | $datalocation = 'site::data'
|
---|
14 | $bar = getvar("${datalocation}::bar")
|
---|
15 | # Equivalent to $bar = $site::data::bar
|
---|
16 | ENDHEREDOC
|
---|
17 |
|
---|
18 | unless args.length == 1
|
---|
19 | raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
|
---|
20 | end
|
---|
21 |
|
---|
22 | begin
|
---|
23 | result = nil
|
---|
24 | catch(:undefined_variable) do
|
---|
25 | result = self.lookupvar("#{args[0]}")
|
---|
26 | end
|
---|
27 |
|
---|
28 | # avoid relying on incosistent behaviour around ruby return values from catch
|
---|
29 | result
|
---|
30 | rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
|
---|
31 | end
|
---|
32 |
|
---|
33 | end
|
---|
34 |
|
---|
35 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.