Class: Kafo::PuppetCommand

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

Instance Method Summary collapse

Constructor Details

#initialize(command, options = []) ⇒ PuppetCommand

Returns a new instance of PuppetCommand.



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

def initialize(command, options = [])
  @command = command

  # 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)}")
  @logger  = KafoConfigure.logger
end

Instance Method Details

#add_progressObject



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

def add_progress
  KafoConfigure.verbose ? '' : "$kafo_add_progress=true"
end

#append(suffix) ⇒ Object



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

def append(suffix)
  @suffix = suffix
  self
end

#commandObject



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

def command
  result = [
      "echo '$kafo_config_file=\"#{KafoConfigure.config_file}\" #{custom_answer_file} #{add_progress} #{@command}'",
      '|',
      "RUBYLIB=#{["#{KafoConfigure.gem_root}/modules", ::ENV['RUBYLIB']].join(File::PATH_SEPARATOR)}",
      "puppet apply #{@options.join(' ')} #{@suffix}",
  ].join(' ')
  @logger.debug result
  result
end

#custom_answer_fileObject



14
15
16
# File 'lib/kafo/puppet_command.rb', line 14

def custom_answer_file
  KafoConfigure.temp_config_file.nil? ? '' : "$kafo_answer_file=\"#{KafoConfigure.temp_config_file}\""
end