Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
942 bytes
|
Line | |
---|
1 | module Puppet::Parser::Functions
|
---|
2 | newfunction(:loadyaml, :type => :rvalue, :arity => -2, :doc => <<-'ENDHEREDOC') do |args|
|
---|
3 | Load a YAML file containing an array, string, or hash, and return the data
|
---|
4 | in the corresponding native data type.
|
---|
5 | The second parameter is the default value. It will be returned if the file
|
---|
6 | was not found or could not be parsed.
|
---|
7 |
|
---|
8 | For example:
|
---|
9 |
|
---|
10 | $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
|
---|
11 | $myhash = loadyaml('no-file.yaml', {'default' => 'value'})
|
---|
12 | ENDHEREDOC
|
---|
13 |
|
---|
14 | raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless args.length >= 1
|
---|
15 | require 'yaml'
|
---|
16 |
|
---|
17 | if File.exists?(args[0])
|
---|
18 | begin
|
---|
19 | YAML::load_file(args[0]) || args[1]
|
---|
20 | rescue Exception => e
|
---|
21 | if args[1]
|
---|
22 | args[1]
|
---|
23 | else
|
---|
24 | raise e
|
---|
25 | end
|
---|
26 | end
|
---|
27 | else
|
---|
28 | warning("Can't load '#{args[0]}' File does not exist!")
|
---|
29 | args[1]
|
---|
30 | end
|
---|
31 |
|
---|
32 | end
|
---|
33 |
|
---|
34 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.