2011-07-25 19:42:27 +02:00
|
|
|
module Puppet::Parser::Functions
|
|
|
|
|
|
|
|
newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
2011-08-18 00:53:27 +02:00
|
|
|
Load a YAML file containing an array, string, or hash, and return the data
|
|
|
|
in the corresponding native data type.
|
2011-07-25 19:42:27 +02:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2011-08-18 00:20:26 +02:00
|
|
|
$myhash = loadyaml('/etc/puppet/data/myhash.yaml')
|
2011-07-25 19:42:27 +02:00
|
|
|
ENDHEREDOC
|
|
|
|
|
|
|
|
unless args.length == 1
|
|
|
|
raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)")
|
|
|
|
end
|
|
|
|
|
2014-09-02 11:35:42 +02:00
|
|
|
if File.exists?(args[0]) then
|
|
|
|
YAML.load_file(args[0])
|
|
|
|
else
|
|
|
|
warning("Can't load " + args[0] + ". File does not exist!")
|
|
|
|
nil
|
|
|
|
end
|
2011-07-25 19:42:27 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|