Last active
March 15, 2017 17:36
-
-
Save acidprime/04ccc3adbc0e957857a85d6a0fd6a9a2 to your computer and use it in GitHub Desktop.
Print aggregate resource lists in older versions of PuppetDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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