Changeset be0859f for src/puppetcode/environments/gnuboat/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb
- Timestamp:
- Jul 31, 2017, 6:42:27 PM (9 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- fc9d514
- Parents:
- eb1ccd6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/puppetcode/environments/gnuboat/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb
reb1ccd6 rbe0859f 1 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. 2 7 3 newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| 4 Load a YAML file containing an array, string, or hash, and return the data 5 in the corresponding native data type. 8 For example: 6 9 7 For example: 10 $myhash = loadyaml('/etc/puppet/data/myhash.yaml') 11 $myhash = loadyaml('no-file.yaml', {'default' => 'value'}) 12 ENDHEREDOC 8 13 9 $myhash = loadyaml('/etc/puppet/data/myhash.yaml')10 ENDHEREDOC14 raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless args.length >= 1 15 require 'yaml' 11 16 12 unless args.length == 1 13 raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)") 14 end 15 16 if File.exists?(args[0]) then 17 YAML.load_file(args[0]) 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 18 27 else 19 warning("Can't load " + args[0] + ".File does not exist!")20 nil28 warning("Can't load '#{args[0]}' File does not exist!") 29 args[1] 21 30 end 22 31
Note:
See TracChangeset
for help on using the changeset viewer.
