Last active
October 27, 2017 14:29
-
-
Save jpadams/de1d5ab6e24f7f1d539e4116d77d86f2 to your computer and use it in GitHub Desktop.
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/puppetlabs/puppet/bin/ruby | |
| require 'json' | |
| puppet = '/opt/puppetlabs/bin/puppet' | |
| today = %x(date +%Y-%m-%d).chomp | |
| nodes_json = JSON.parse(%x(#{puppet} query 'nodes[certname] { deactivated is null }')) | |
| nodes_list = nodes_json.map { |n| n.values }.flatten | |
| nodes_list.each { |node| | |
| puts "Saving #{node} facts to disk" | |
| %x(mkdir -p #{node}) | |
| #facts = %x(#{puppet} query 'facts[name, value] { certname = "#{node}" }') | |
| facts = %x(#{puppet} query 'facts[] { certname = "#{node}" }') | |
| outfile = "#{node}/#{node}-#{today}.json" | |
| open(outfile, 'w') { |out| out.print facts } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment