Module: CemAcpt::Utils::PuppetUtils

Defined in:
lib/cem_acpt/utils.rb

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

.puppet_executableObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cem_acpt/utils.rb', line 24

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