Is there a way to find unused puppet code (2.7)?

440 views
Skip to first unread message

Amos Shapira

unread,
Feb 9, 2014, 1:53:38 AM2/9/14
to puppet...@googlegroups.com
Hello,

Is there a way to systematically find all modules we have which aren't used?

Two reasons for this question:
  1. We use librarian-puppet to manage "external" modules and would like to find which of them can we remove.
  2. We did some major refactoring over the years, in particular we moved from a mix of old distribution to a single Ubuntu LTS version, and there could be some of our own classes which aren't used.
  3. If it's an automatic way, it will be great to run it as part of our Continuous Integration suite to find code which can be removed.
So - is there such a thing?

Cheers,

--Amos

José Luis Ledesma

unread,
Feb 9, 2014, 7:42:01 AM2/9/14
to puppet...@googlegroups.com

I was thinking about this too.

If your servers checkin every 30 minutos you can do:
find /path/to/modules  -amin +30

I have not tried it yet,but I suppose it works

Regards,

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/3481c943-4b09-4029-ad98-8f2906023340%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Amos Shapira

unread,
Feb 9, 2014, 7:52:20 AM2/9/14
to puppet...@googlegroups.com
I don't think it'll work, even though my servers do check in every 30 minutes:
  1. From what I understand, the puppet master caches the manifest and doesn't re-interpret it unless it changed.
  2. I have atime disabled on my servers. It saves tons of disk IO and is even the default on our platform (Ubuntu 12.04 LTS).
I have a gut feeling that once Puppet interprets the manifest, it holds a tree of objects somewhere were I can scan and look for mention of every class in my Puppet source. I just found /var/lib/puppet/state/state.yaml, which has an entry for resource, including classes. Perhaps that's the direction to go but I was wondering whether there is already a tool to do that.

Henrik Lindberg

unread,
Feb 9, 2014, 4:36:54 PM2/9/14
to puppet...@googlegroups.com
On 2014-09-02 2:53, Amos Shapira wrote:
> Hello,
>
> Is there a way to systematically find all modules we have which aren't used?
>
Basically, the answer is "no" because it is not possible to statically
analyze puppet code since all inputs are unknown. (This because
references to types can be dynamic - i.e. based on combination of values
that are only present when evaluation takes place).

At best, it is possible to find candidates that *may* be removed, but
only with knowledge that there are no dynamic references, and/or after
testing.

Having a tool that finds modules that a given module depends on but
without anything actually being used is a great tool to have - suggest
filing an enhancement request for Geppetto for this. (It will still not
be able to tell you if there are dynamic references - only testing
can answer that).

Regards
- henrik


gh

unread,
Feb 9, 2014, 4:43:47 PM2/9/14
to puppet...@googlegroups.com
On 2/8/14 8:53 PM, Amos Shapira wrote:
> Hello,
>
> Is there a way to systematically find all modules we have which aren't used?
>
> Two reasons for this question:
>
> 1. We use librarian-puppet to manage "external" modules and would like
> to find which of them can we remove.
> 2. We did some major refactoring over the years, in particular we moved
> from a mix of old distribution to a single Ubuntu LTS version, and
> there could be some of our own classes which aren't used.
> 3. If it's an automatic way, it will be great to run it as part of our
> Continuous Integration suite to find code which can be removed.
>
> So - is there such a thing?
>
> Cheers,
>
> --Amos


Hi Amos,

With PuppetDB you can query[1] for the most recent catalog of a given
node which will list all of the classes used. You could the use the
process of elimination to see what classes you had in your modulepath
that are not showing up in your catalogs.

[1] - http://docs.puppetlabs.com/puppetdb/1.6/api/query/v3/catalogs.html

BR,
-g

--
Garrett Honeycutt
learnpuppet.com

Henrik Lindberg

unread,
Feb 10, 2014, 2:02:32 AM2/10/14
to puppet...@googlegroups.com
I logged a feature issue for Geppetto -
https://tickets.puppetlabs.com/browse/PUP-1625

Regards
- henrik


Reply all
Reply to author
Forward
0 new messages