class Kafo::PuppetCommand

Public Class Methods

new(command, options = [], puppet_config = nil, configuration = KafoConfigure.config) click to toggle source
# File lib/kafo/puppet_command.rb, line 3
def initialize(command, options = [], puppet_config = nil, configuration = KafoConfigure.config)
  @configuration = configuration
  @command = command
  @puppet_config = puppet_config

  # Expand the modules_path to work around the fact that Puppet doesn't
  # allow modulepath to contain relative (i.e ..) directory references as
  # of 2.7.23.
  @options = options.push("--modulepath #{File.expand_path(modules_path)}")
  @options.push("--config=#{puppet_config.config_path}") if puppet_config
  @logger  = KafoConfigure.logger
end
search_puppet_path(bin_name) click to toggle source
# File lib/kafo/puppet_command.rb, line 37
def self.search_puppet_path(bin_name)
  bin_path = (::ENV['PATH'].split(File::PATH_SEPARATOR) + ['/opt/puppetlabs/bin']).find do |path|
    File.executable?(File.join(path, bin_name))
  end
  File.join([bin_path, bin_name].compact)
end

Public Instance Methods

add_progress() click to toggle source
# File lib/kafo/puppet_command.rb, line 16
def add_progress
  %Q{$kafo_add_progress="#{!KafoConfigure.verbose}"}
end
append(suffix) click to toggle source
# File lib/kafo/puppet_command.rb, line 32
def append(suffix)
  @suffix = suffix
  self
end
command() click to toggle source
# File lib/kafo/puppet_command.rb, line 20
def command
  @puppet_config.write_config if @puppet_config
  result = [
      "echo '$kafo_config_file=\"#{@configuration.config_file}\" #{add_progress} #{@command}'",
      '|',
      "RUBYLIB=#{[@configuration.kafo_modules_dir, ::ENV['RUBYLIB']].join(File::PATH_SEPARATOR)}",
      "#{puppet_path} apply #{@options.join(' ')} #{@suffix}",
  ].join(' ')
  @logger.debug result
  result
end

Private Instance Methods

modules_path() click to toggle source
# File lib/kafo/puppet_command.rb, line 46
def modules_path
  [
      @configuration.module_dirs,
      @configuration.kafo_modules_dir,
  ].flatten.join(':')
end
puppet_path() click to toggle source
# File lib/kafo/puppet_command.rb, line 53
def puppet_path
  @puppet_path ||= self.class.search_puppet_path('puppet')
end