diff options
author | David Schmitt <david.schmitt@puppetlabs.com> | 2015-10-15 09:44:12 +0100 |
---|---|---|
committer | David Schmitt <david.schmitt@puppetlabs.com> | 2015-10-15 09:44:12 +0100 |
commit | 57a8485223c221aa075d09c0a7de816a26daf1b0 (patch) | |
tree | 556730758a11a2e2d42a60d43e553b7abcdf5c4c /lib | |
parent | 5b3c623394e405ca0db5e707554a91b4252bbbad (diff) | |
parent | 25410c4598d3c0029fcd05adc2e305dbf5f8d902 (diff) |
Merge pull request #537 from cmurphy/fix_load_module_metadata
Fix load module metadata
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/functions/load_module_metadata.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/puppet/parser/functions/load_module_metadata.rb b/lib/puppet/parser/functions/load_module_metadata.rb index 0664a23..c9b8488 100644 --- a/lib/puppet/parser/functions/load_module_metadata.rb +++ b/lib/puppet/parser/functions/load_module_metadata.rb @@ -2,14 +2,22 @@ module Puppet::Parser::Functions newfunction(:load_module_metadata, :type => :rvalue, :doc => <<-EOT EOT ) do |args| - raise(Puppet::ParseError, "load_module_metadata(): Wrong number of arguments, expects one") unless args.size == 1 + raise(Puppet::ParseError, "load_module_metadata(): Wrong number of arguments, expects one or two") unless [1,2].include?(args.size) mod = args[0] + allow_empty_metadata = args[1] module_path = function_get_module_path([mod]) metadata_json = File.join(module_path, 'metadata.json') - raise(Puppet::ParseError, "load_module_metadata(): No metadata.json file for module #{mod}") unless File.exists?(metadata_json) - - metadata = PSON.load(File.read(metadata_json)) + metadata_exists = File.exists?(metadata_json) + if metadata_exists + metadata = PSON.load(File.read(metadata_json)) + else + if allow_empty_metadata + metadata = {} + else + raise(Puppet::ParseError, "load_module_metadata(): No metadata.json file for module #{mod}") + end + end return metadata end |