Class: Skewer::Puppet

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

Overview

responsible for executing puppet

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(node, options) ⇒ Object



48
49
50
51
# File 'lib/puppet.rb', line 48

def self.run(node, options)
  this = self.new
  this.run(node, options)
end

Instance Method Details

#argumentsObject



7
8
9
10
11
12
# File 'lib/puppet.rb', line 7

def arguments
  [
   "--modulepath modules",
   "--vardir /var/lib/puppet"
  ].join(' ')
end

#bundleObject



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

def bundle
  "/var/lib/gems/1.8/bin/bundle"
end

#command_string(username, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet.rb', line 18

def command_string(username, options)
  @command_line = "cd infrastructure"
  if username == 'root'
    @command_line << " &&"
  else
    @command_line <<  " && sudo"
  end
  @command_line << " #{self.bundle} exec"
  @command_line << " puppet apply"
  @command_line << " manifests/site.pp"
  @command_line << " --color false"
  @command_line << " #{arguments}"
  if options[:noop]
    @command_line << " --noop"
  end
  @command_line
end

#run(node, options) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet.rb', line 36

def run(node, options)
  command = command_string(node.username, options)
  result = node.ssh(command)[0]
  if result.status != 0
    Skewer.logger.debug result.stdout
    raise PuppetRuntimeError, "Puppet failed"
  else
    Skewer.logger.debug "Puppet run succeeded"
  end
  result
end