Skip to content

Instantly share code, notes, and snippets.

@kbarber
Created March 14, 2014 23:21
Show Gist options
  • Save kbarber/9559108 to your computer and use it in GitHub Desktop.
Save kbarber/9559108 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'facter'
uri = URI.parse("http://localhost:8080/v3/commands")
http = Net::HTTP.new(uri.host, uri.port)
facts = {}
Facter.to_hash.each do |k,v|
facts[k] = v.to_s
end
hostname = facts["fqdn"]
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(
{
"payload" => {
"command" => "replace facts",
"version" => 1,
"payload" => {
"name" => hostname,
"values" => facts,
}.to_json,
}.to_json
}
)
response = http.request(request)
puts response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment