puppet-ghostbuster

Build Status Gem Version Gem Downloads Gemnasium

When you have dead puppet code hanging around ... Who you gonna call ?

This gems helps puppet users to find dead code by displaying unused classes, defined resources, template and files.

This gems only support PuppetDB APi v4 (PuppetDB 3+)

Usage

If you want to read default options and private key from puppet configuration, this gem needs to have root (puppet) permissions.

sudo bundle exec puppet-ghostbuster

You can add preconnect command with -p and server url with -s.

-h or --help for full options.

Example output

$ bundle exec puppet-ghostbuster -s https://puppetdburl:8081
Class Foo::Install not used
Class Foo::Service not used
Class Foo not used
...
Define Bar::Baz not used
...
Template ./modulename/templates/foo.erb not used
Template ./modulename/templates/bar.erb not used
Template ./modulename/templates/baz.erb not used
...
File ./foo/files/bar.txt not used
File ./foo/files/baz.txt not used
...

How It Works

To find unused classes:

  1. It search puppet code recursively starting (by default) from current directory.
  2. For each .pp file found, it extract the class name
  3. Query puppetdb (using cache) to find matching class in catalogs
  4. Display the number of class, followed by the class name.

Same method applies to find unused defines.

To find template and files, it has to loop twice, so this step can be longer.

.ghostbusterignore

Puppet-ghostbuster supports .ghostbusterignore files with a list of path that will be excluded from the dead code detection. Useful for upstream modules where you are are not using everything.

Example of .ghostbusterignore file:

modules/apache
modules/mysql
modules/mcollective/templates