Puppet Function: load_module_metadata

Defined in:
lib/puppet/parser/functions/load_module_metadata.rb
Function type:
Ruby 3.x API

Overview

load_module_metadata()Any

This function loads the metadata of a given module.

Returns:

  • (Any)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/parser/functions/load_module_metadata.rb', line 5

newfunction(:load_module_metadata, :type => :rvalue, :doc => <<-DOC
  This function loads the metadata of a given module.
DOC
           ) do |args|
  raise(Puppet::ParseError, 'load_module_metadata(): Wrong number of arguments, expects one or two') unless [1, 2].include?(args.size)
  mod = args[0]
   = args[1]
  module_path = function_get_module_path([mod])
   = File.join(module_path, 'metadata.json')

   = File.exists?() # rubocop:disable Lint/DeprecatedClassMethods : Changing to .exist? breaks the code
  if 
     = PSON.load(File.read())
  else
     = {}
    raise(Puppet::ParseError, "load_module_metadata(): No metadata.json file for module #{mod}") unless 
  end

  return 
end