lib/marionette/puppet.rb in marionette-0.0.12 vs lib/marionette/puppet.rb in marionette-0.0.13
- old
+ new
@@ -4,16 +4,15 @@
require 'uri'
# Puppet class is the active ZMQ connection on the puppet node
class Puppet
- attr_accessor :socket, :thread, :message
+ attr_accessor :socket, :thread, :messages
def initialize(socket)
@socket = socket
- @messages = []
start
end
# Starts send and response thread
@@ -31,11 +30,11 @@
# Stand by for a response msg
@response = @socket.recv
# Sets default message to current time
- @message << "Response from node @ #{Time.now}."
+ @messages = ["Response from node @ #{Time.now}."]
begin
# Execute a puppet run and/or ad hoc system commands
@response = Marshal.load(@response)
@@ -74,32 +73,35 @@
end
# Executes ad hoc system command msg'd from the master
def system_run
- @message << `#{@response[:system][:command]}`
+ @messages << `#{@response[:system][:command]}`
end
# Executes a puppet run
def puppet_run
if @response[:puppet].nil?
- @message << `puppet agent --server master.runrails.com --verbose --waitforcert 5 --no-daemonize --onetime --logdest /var/log/puppet.log`
+ @messages << `puppet agent --server master.runrails.com --verbose --waitforcert 5 --no-daemonize --onetime --logdest /var/log/puppet.log`
else
- @message << `puppet agent #{@response[:puppet][:args]}`
+ @messages << `puppet agent #{@response[:puppet][:args]}`
end
end
# Fetches facts collection
def facter_run
# Load facts from cli to reduce ruby memory footprint
- facts = `facter`
- facts = facts.split "\n"
- facts.collect! {|f| ff=f.split("=>"); {ff[0].strip.to_sym => ff[1]}}.compact
- @message << facts
+ facts = {}
+ raw = `facter`
+ raw.split("\n").each do |line|
+ fact = line.split(" => ")
+ facts[fact[0].strip.to_sym] = fact[1].strip
+ end
+ @messages << facts
end
end