Puppet Function: simplib::module_exist

Defined in:
lib/puppet/functions/simplib/module_exist.rb
Function type:
Ruby 4.x API

Overview

simplib::module_exist(String[1] $module_name)Boolean

Determines if a module exists in the current environment

If passed with an author, such as ‘simp/simplib` or `simp-simplib`, will return whether or not that specific module exists.

Parameters:

  • module_name (String[1])

    The module name to check

Returns:

  • (Boolean)

    Whether or not the module exists in the current environment



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
33
34
35
# File 'lib/puppet/functions/simplib/module_exist.rb', line 5

Puppet::Functions.create_function(:'simplib::module_exist') do

  # @param module_name The module name to check
  # @return [Boolean] Whether or not the module exists in the current environment
  dispatch :module_exist do
    required_param 'String[1]', :module_name
  end

  def module_exist(module_name)
    _module_author, _module_name = module_name.split(%r(/|-))

    unless _module_name
      _module_name = _module_author.dup
      _module_author = nil
    end

    if Puppet::Module.find(_module_name, closure_scope.compiler.environment.to_s)
      if _module_author
        if _module_author.strip == call_function('load_module_metadata', _module_name)['name'].strip.split(%r(/|-)).first
          return true
        else
          return false
        end
      else
        return true
      end
    else
      return false
    end
  end
end