Class: Kafo::PuppetCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/puppet_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options = [], puppet_config = nil, configuration = KafoConfigure.config) ⇒ PuppetCommand

Returns a new instance of PuppetCommand.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/kafo/puppet_command.rb', line 4

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

Class Method Details

.search_puppet_path(bin_name) ⇒ Object



38
39
40
41
42
43
# File 'lib/kafo/puppet_command.rb', line 38

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

Instance Method Details

#add_progressObject



17
18
19
# File 'lib/kafo/puppet_command.rb', line 17

def add_progress
  %{$kafo_add_progress="#{!KafoConfigure.verbose}"}
end

#append(suffix) ⇒ Object



33
34
35
36
# File 'lib/kafo/puppet_command.rb', line 33

def append(suffix)
  @suffix = suffix
  self
end

#commandObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kafo/puppet_command.rb', line 21

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