Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active March 15, 2017 17:36
Show Gist options
  • Save acidprime/04ccc3adbc0e957857a85d6a0fd6a9a2 to your computer and use it in GitHub Desktop.
Save acidprime/04ccc3adbc0e957857a85d6a0fd6a9a2 to your computer and use it in GitHub Desktop.
Print aggregate resource lists in older versions of PuppetDB
#!/opt/puppet/bin/ruby
require 'net/http'
require 'uri'
require 'json'
def cputs(string)
puts "\033[1m#{string}\033[0m"
end
check_resource = ARGV[0]
uri = URI("http://localhost:8080/v3/resources/#{check_resource.capitalize}")
response = Net::HTTP.get_response(uri)
resources = JSON.parse(response.body)
nodes = Hash.new
resources.each do |resource|
(nodes[resource['title']] ||= []) << resource['certname']
end
nodes.each do |title,node_list|
puts '-' * 80
cputs title
puts '-' * 80
puts node_list.join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment