From b75862abf9f8001f671f5fc603ffcfb981797231 Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Fri, 3 Jan 2014 14:56:14 +0000 Subject: [PATCH] Add a new puppet face Signed-off-by: Stephen Gran --- .../lib/puppet/face/catalog/print.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/parselocalconfig/lib/puppet/face/catalog/print.rb diff --git a/modules/parselocalconfig/lib/puppet/face/catalog/print.rb b/modules/parselocalconfig/lib/puppet/face/catalog/print.rb new file mode 100644 index 000000000..f8ec4c913 --- /dev/null +++ b/modules/parselocalconfig/lib/puppet/face/catalog/print.rb @@ -0,0 +1,80 @@ +require 'puppet/face' + +Puppet::Face.define(:catalog, '0.0.1') do + action :print do + summary "Displays the contents of a catalog" + + option "--catalog CATALOG" do + summary "Path to a specific catalog to print" + end + + option "--limit TYPE" do + summary "Limits the display to a certain type" + end + + option "--no-classes" do + summary "Do not show any classes" + end + + option "--no-resources" do + summary "Do not show resources list" + end + + option "--no-tags" do + summary "Do not show any tags" + end + + + when_invoked do |options| + Puppet.settings.preferred_run_mode = "agent" + + catalog_file = options.fetch(:catalog, File.join([Puppet[:client_datadir], "catalog", "%s.json" % Puppet[:certname]])) + + catalog = PSON.parse(File.read(catalog_file)) + + unless options[:no_classes] == false + puts("Classes included on this node:") + catalog.classes.each do |klass| + puts("\t#{klass}") + end + + puts("\n\n") + end + + unless options[:no_tags] == false + puts("Tags for this node:") + catalog.tags.each do |tag| + puts("\t#{tag}") + end + + puts("\n\n") + end + + unless options[:no_resources] == false + puts("Resources managed by puppet on this node:") + printresource(catalog, options[:limit]) + end + + nil + end + end + + def printresource(resource, limit) + if resource.class == Puppet::Resource::Catalog + resource.edges.each do |b| + printresource(b, limit) + end + elsif resource.class == Puppet::Relationship and resource.target.class == Puppet::Resource and resource.target.title != nil and resource.target.file != nil + target = resource.target + manifestfile = target.file.gsub("/etc/puppet/manifests/", "") + + if limit + if target.type.downcase == limit.downcase + puts "\t#{target.type} { #{target.title}: }\n\t\tdefined in #{manifestfile}:#{target.line}\n\n" + end + else + puts "\t#{target.type} { #{target.title}: }\n\t\tdefined in #{manifestfile}:#{target.line}\n\n" + end + end + end +end -- 2.20.1