Sha256: 15e5bc25e8169155ec0f6ddf1380d2bfb8bef369ce6da73dabe81d88fb16a9ad
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
### http client module Runpuppet class Agent attr_accessor :config attr_accessor :run_options def initialize(context) @config = context.config @run_options = context.run_options end ##### puppet def check_status begin r = get("/puppet/run") rescue Exception => e end if r return (action, branch = *r.split('-')) else return nil end end def report_start get '/puppet/status?status=started' end def report_success get '/puppet/status?status=finished' end def report_failure get '/puppet/status?status=error' end def report_facts require 'facter/application' facts = Facter::Application.run([]) post('/puppet/facts', :facts => facts.to_hash) end #### base 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 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 def append_params_to_post(params) params = params.dup params[:hostname] = config.hostname params[:ip] = config.local_ip return params end def append_params_to_url(url) url += (url.include?('?') ? '&' : '?') url += "hostname=#{config.hostname}&ip=#{config.local_ip}" url end def base_url(path) "#{config.puppet_controller_url.gsub(/\/$/, '')}/#{path.gsub(/^\//, '')}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
runpuppet-1.0.2 | lib/runpuppet/agent.rb |