From: Angel L. Mateo Date: Tue, 2 Sep 2014 09:35:42 +0000 (+0200) Subject: Check if file exists before loading with loadyaml. If not, return nil X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=b9560df899fdea34ac69692ef2447ffdd2d3365a;p=puppet-stdlib.git Check if file exists before loading with loadyaml. If not, return nil --- diff --git a/lib/puppet/parser/functions/loadyaml.rb b/lib/puppet/parser/functions/loadyaml.rb index 10c4005..ca655f6 100644 --- a/lib/puppet/parser/functions/loadyaml.rb +++ b/lib/puppet/parser/functions/loadyaml.rb @@ -13,7 +13,12 @@ module Puppet::Parser::Functions raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)") end - YAML.load_file(args[0]) + if File.exists?(args[0]) then + YAML.load_file(args[0]) + else + warning("Can't load " + args[0] + ". File does not exist!") + nil + end end