Puppet Function: load_module_metadata

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

Overview

load_module_metadata()Any

Examples:

Example USage:

$metadata = load_module_metadata('archive')
notify { $metadata['author']: }

Returns:

  • (Any)

    The modules metadata



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'modules/stdlib/lib/puppet/parser/functions/load_module_metadata.rb', line 5

newfunction(:load_module_metadata, :type => :rvalue, :doc => <<-DOC
  @summary
    This function loads the metadata of a given module.

  @example Example USage:
    $metadata = load_module_metadata('archive')
    notify { $metadata['author']: }

  @return
    The modules metadata
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