Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active March 14, 2017 14:34
Show Gist options
  • Save acidprime/93db6c35d2f660730b815dca722e69b8 to your computer and use it in GitHub Desktop.
Save acidprime/93db6c35d2f660730b815dca722e69b8 to your computer and use it in GitHub Desktop.
Read puppet yamlcache and make tables from the facts
#!/usr/bin/env ruby
require 'puppet'
require 'terminal-table'
output = Hash.new
Factspath = ARGV[0]
FACTS = ['osfamily','lsbmajdistrelease','puppetversion','rubyversion','virtual','architecture','role','gpu','location']
#raise "Must pass facts directory as postional parameter 1" unless Dir.exists?(Factspath) or Factspath.nil?
Dir.glob("#{Factspath}/*.yaml") do |filepath|
facts_hash = YAML.load_file(filepath)
FACTS.each do |fact|
output[fact.to_sym] ||= Hash.new
(output[fact.to_sym][facts_hash.values[fact.to_s]] ||= []) << facts_hash.values['fqdn']
end
end
output.each do |fact,hash|
table = Terminal::Table.new(:headings => [fact, 'Count']) do |t|
hash.each do |k,v|
t << :separator
t.add_row [k,v.length]
end
end
puts table
end
~
@acidprime
Copy link
Author

acidprime commented Mar 14, 2017

./fact_yaml_print.rb `puppet agent --configprint yamldir`/facts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment