Last active
March 14, 2017 14:34
-
-
Save acidprime/93db6c35d2f660730b815dca722e69b8 to your computer and use it in GitHub Desktop.
Read puppet yamlcache and make tables from the facts
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
#!/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 | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./fact_yaml_print.rb `puppet agent --configprint yamldir`/facts