class Run

A basic class for running the agent. Used by `puppet kick` to kick off agents remotely.

Public Class Methods

from_pson( pson ) click to toggle source
# File lib/puppet/run.rb, line 66
def self.from_pson( pson )
  options = { :pluginsync => Puppet[:pluginsync] }
  pson.each do |key, value|
    options[key.to_sym] = value
  end

  new(options)
end
new(options = {}) click to toggle source
# File lib/puppet/run.rb, line 22
def initialize(options = {})
  if options.include?(:background)
    @background = options[:background]
    options.delete(:background)
  end

  valid_options = [:tags, :ignoreschedules, :pluginsync]
  options.each do |key, value|
    raise ArgumentError, "Run does not accept #{key}" unless valid_options.include?(key)
  end

  @options = options
end

Public Instance Methods

agent() click to toggle source
# File lib/puppet/run.rb, line 13
def agent
  # Forking disabled for "puppet kick" runs
  Puppet::Agent.new(Puppet::Configurer, false)
end
background?() click to toggle source
# File lib/puppet/run.rb, line 18
def background?
  background
end
log_run() click to toggle source
# File lib/puppet/run.rb, line 36
def log_run
  msg = ""
  msg += "triggered run" % if options[:tags]
    msg += " with tags #{options[:tags].inspect}"
  end

  msg += " ignoring schedules" if options[:ignoreschedules]

  Puppet.notice msg
end
run() click to toggle source
# File lib/puppet/run.rb, line 47
def run
  if agent.running?
    @status = "running"
    return self
  end

  log_run

  if background?
    Thread.new { agent.run(options) }
  else
    agent.run(options)
  end

  @status = "success"

  self
end
to_pson() click to toggle source
# File lib/puppet/run.rb, line 75
def to_pson
  @options.merge(:background => @background).to_pson
end