Puppet – Identifying dead puppet code using puppet ghostbuster

This is a how-to guide on using:


First get this working so that you can access this gui dashboard:


Install rvm:

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby

Check rvm install is successful:

schowdhury@Shers-MacBook-Pro:~$ rvm --version
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
schowdhury@Shers-MacBook-Pro:~$ rvm list

rvm rubies

=* ruby-2.4.1 [ x86_64 ]

# => - current
# =* - current && default
# * - default

schowdhury@Shers-MacBook-Pro:~$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

Next install the following gems:

gem install puppet-ghostbuster
gem install r10k

Then clone your repo onto your laptop, and while in this repo, switch to the appropriate branch, then run:

$ r10k puppetfile install --verbose

then in a seperate bash terminal tab, run:

$ ssh -L 8080:localhost:8080 {puppetmaster-fqdn}

Now test this ssh tunnel by opening up a web browser and went to:

This is a bit of ‘hello world’ test .

For reference: https://docs.puppet.com/puppetdb/latest/maintain_and_tune.html#monitor-the-performance-dashboard

Another test you can do:

$ cat ~/identify-obsolete-modules.json
["=", "environment", "dev"],
["=", "type", "Class"],
["~", "title", "."]]

$ curl -s -G http://localhost:8080/pdb/query/v4/resources --data-urlencode 'pretty=true' --data-urlencode query@identify-obsolete-modules.json | grep title | cut -d'"' -f4 | awk 'BEGIN {FS="::"} {print $1}' | sort | uniq

then take a copy of your puppetmaster’s hiera.yaml file and place it somewhere on your laptop, then run the following command:

$ PUPPETDB_URL='http://localhost:8080/' HIERA_YAML_PATH='/path/to/local/hiera.yaml' find . -type f -exec puppet-lint --only-checks ghostbuster_classes {} \+

Here we just used the ghostbuster_classes plugin, but there are all these available too: