Skip to content

Instantly share code, notes, and snippets.

@op-ct
Forked from happymcplaksin/pupcat.rb
Last active September 29, 2020 20:57
Show Gist options
  • Save op-ct/4e901c75a86fbff157a52ce6f5ba15d0 to your computer and use it in GitHub Desktop.
Save op-ct/4e901c75a86fbff157a52ce6f5ba15d0 to your computer and use it in GitHub Desktop.
pupcat.rb
#!/usr/bin/ruby
require 'rubygems'
require 'json'
require 'yaml'
user = ARGV[0] || %x{id -u -n}.strip
if user == 'root'
dir = '/opt/puppetlabs/puppet/cache/client_data/catalog/'
else
dir = "/home/#{user}/.puppetlabs/var/client_data/catalog/"
end
unless File.directory? dir
fail "Sorry, I don't know where to find the catalog for user '#{user}'"
end
cat = JSON.load(File.readlines("#{dir}/#{ENV['HOSTNAME']}.json").join)
print cat.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment