Module: CemAcpt::Utils::Puppet

Defined in:
lib/cem_acpt/utils.rb

Overview

Puppet-related utilities

Constant Summary collapse

DEFAULT_PUPPET_PATH =
{
  nix: '/opt/puppetlabs/bin/puppet',
  windows: 'C:/Program Files/Puppet Labs/Puppet/bin/puppet.bat',
}.freeze

Class Method Summary collapse

Class Method Details

.build_module_package(module_dir, target_dir = nil, should_log: false) ⇒ String

Builds a Puppet module package.

Parameters:

  • module_dir (String)

    Path to the module directory. If target_dir is specified as a relative path, it will be relative to the module dir.

  • target_dir (String) (defaults to: nil)

    Path to the target directory where the package will be built. This defaults to the relative path 'pkg/'.

  • should_log (Boolean) (defaults to: false)

    Whether or not to log the build process.

Returns:

  • (String)

    Path to the built package.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cem_acpt/utils.rb', line 59

def self.build_module_package(module_dir, target_dir = nil, should_log: false)
  require 'puppet/modulebuilder'
  require 'fileutils'

  builder_logger = should_log ? logger : nil
  builder = ::Puppet::Modulebuilder::Builder.new(::File.expand_path(module_dir), target_dir, builder_logger)

  # Validates module metadata by raising exception if invalid
   = builder.

  # Builds the module package
  builder.build
end

.puppet_executableObject

Finds and returns the Puppet executable



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cem_acpt/utils.rb', line 33

def self.puppet_executable
  this_os = CemAcpt::Utils.os
  if File.file?(DEFAULT_PUPPET_PATH[this_os]) && File.executable?(DEFAULT_PUPPET_PATH[this_os])
    return DEFAULT_PUPPET_PATH[this_os]
  end

  file_name = 'puppet'
  if this_os == :windows
    exts = ENV['PATHEXT'] ? ".{#{ENV['PATHEXT'].tr(';', ',').tr('.', '').downcase}}" : '.{exe,com,bat}'
    file_name = "#{file_name}#{exts}"
  end
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    if File.file?(File.join(path, file_name)) && File.executable?(File.join(path, file_name))
      return File.join(path, file_name)
    end
  end
  raise 'Could not find Puppet executable! Is Puppet installed?'
end