3 Puppet::Face.define(:catalog, '0.0.1') do
5 summary "Displays the contents of a catalog"
7 option "--catalog CATALOG" do
8 summary "Path to a specific catalog to print"
11 option "--limit TYPE" do
12 summary "Limits the display to a certain type"
15 option "--no-classes" do
16 summary "Do not show any classes"
19 option "--no-resources" do
20 summary "Do not show resources list"
24 summary "Do not show any tags"
28 when_invoked do |options|
29 Puppet.settings.preferred_run_mode = "agent"
31 catalog_file = options.fetch(:catalog, File.join([Puppet[:client_datadir], "catalog", "%s.json" % Puppet[:certname]]))
33 catalog = PSON.parse(File.read(catalog_file))
35 unless options[:no_classes] == false
36 puts("Classes included on this node:")
37 catalog.classes.each do |klass|
44 unless options[:no_tags] == false
45 puts("Tags for this node:")
46 catalog.tags.each do |tag|
53 unless options[:no_resources] == false
54 puts("Resources managed by puppet on this node:")
55 printresource(catalog, options[:limit])
62 def printresource(resource, limit)
63 if resource.class == Puppet::Resource::Catalog
64 resource.edges.each do |b|
65 printresource(b, limit)
67 elsif resource.class == Puppet::Relationship and resource.target.class == Puppet::Resource and resource.target.title != nil and resource.target.file != nil
68 target = resource.target
69 manifestfile = target.file.gsub("/etc/puppet/manifests/", "")
72 if target.type.downcase == limit.downcase
73 puts "\t#{target.type} { #{target.title}: }\n\t\tdefined in #{manifestfile}:#{target.line}\n\n"
76 puts "\t#{target.type} { #{target.title}: }\n\t\tdefined in #{manifestfile}:#{target.line}\n\n"