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.
10 $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
11 $myhash = loadyaml('no-file.yaml', {'default' => 'value'})
14 raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless args.length >= 1
17 if File.exists?(args[0])
19 YAML::load_file(args[0]) || args[1]
28 warning("Can't load '#{args[0]}' File does not exist!")