Skip to content

Instantly share code, notes, and snippets.

@jpadams
Last active October 27, 2017 14:29
Show Gist options
  • Select an option

  • Save jpadams/de1d5ab6e24f7f1d539e4116d77d86f2 to your computer and use it in GitHub Desktop.

Select an option

Save jpadams/de1d5ab6e24f7f1d539e4116d77d86f2 to your computer and use it in GitHub Desktop.
#!/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