class Runpuppet::Agent

Attributes

config[RW]
run_options[RW]

Public Class Methods

new(context) click to toggle source
# File lib/runpuppet/agent.rb, line 6
def initialize(context)
  @config      = context.config
  @run_options = context.run_options
end

Public Instance Methods

append_params_to_post(params) click to toggle source
# File lib/runpuppet/agent.rb, line 68
def append_params_to_post(params)
  params            = params.dup
  params[:hostname] = config.hostname
  params[:ip]       = config.local_ip
  return params
end
append_params_to_url(url) click to toggle source
# File lib/runpuppet/agent.rb, line 75
def append_params_to_url(url)
  url += (url.include?('?') ? '&' : '?')
  url += "hostname=#{config.hostname}&ip=#{config.local_ip}"
  url
end
base_url(path) click to toggle source
# File lib/runpuppet/agent.rb, line 81
def base_url(path)
  "#{config.puppet_controller_url.gsub(/\/$/, '')}/#{path.gsub(/^\//, '')}"
end
check_status() click to toggle source

puppet

# File lib/runpuppet/agent.rb, line 13
def check_status
  begin
    r = get("/puppet/run")
  rescue Exception => e
  end

  if r
    return (action, branch = *r.split('-'))
  else
    return nil
  end
end
get(path) click to toggle source

base

# File lib/runpuppet/agent.rb, line 46
def get(path)
  begin
    url = append_params_to_url(base_url(path))
    puts "Getting #{url}" if run_options[:debug]
    result = RestClient.get(url)
    puts "got #{result}" if run_options[:debug]
    return result
  rescue Exception => e
    puts e.inspect
    puts "WARNING: error connecting in GET (PuppetMaster)"
  end
end
post(path, params) click to toggle source
# File lib/runpuppet/agent.rb, line 59
def post(path, params)
  begin
    RestClient.post base_url(path), append_params_to_post(params)
  rescue Exception => e
    puts e.inspect
    puts "WARNING: error connecting in POST (PuppetMaster)"
  end
end
report_facts() click to toggle source
# File lib/runpuppet/agent.rb, line 38
def report_facts
  require 'facter/application'
  facts = Facter::Application.run([])
  post('/puppet/facts', :facts => facts.to_hash)
end
report_failure() click to toggle source
# File lib/runpuppet/agent.rb, line 34
def report_failure
  get '/puppet/status?status=error'
end
report_start() click to toggle source
# File lib/runpuppet/agent.rb, line 26
def report_start
  get '/puppet/status?status=started'
end
report_success() click to toggle source
# File lib/runpuppet/agent.rb, line 30
def report_success
  get '/puppet/status?status=finished'
end