Bitfield Consulting

View Original

Dependency graphs in Puppet

Puppet dependencies

Ever seen this message?


Puppet: could not find dependency group for user 'foo' at...

Puppet lets you specify a dependency between two resources, or to put it another way, that one thing should happen before another. Sometimes, though, the chain of dependencies becomes so complex that you accidentally create a circular dependency, which Puppet doesn’t like.


err: Could not apply complete catalog: Found dependency cycles in the following
relationships: Package[ntp] => Service[ntpd], Service[ntpd] => Package[ntp]

When the chain of dependencies is a long one, it can be hard to debug this. I tweeted mournfully that a diagram of the dependencies would be useful:

The vastly knowledgeable @ripienaar and @adamhjk soon put me right: yes, Virginia, you can get Puppet to draw a graph of your resource dependencies. In fact, this was discussed on the Puppet mailing list some time ago.

All you need to do is specify the --graph option to puppetd, or turn it on in your puppet.conf file. Puppet will automatically create DOT files describing the graph of dependencies in the client’s manifest.

These files will end up in your graphdir - by default, /var/puppet/state/graphs. You can view these files by opening them directly in the superb OmniGraffle, if you have it, or using the dot tool (part of GraphViz).

In fact, recent versions of Puppet give you this hint directly:


err: Could not apply complete catalog: Found dependency cycles
in the following relationships: Package[ntp] => Service[ntpd],
Service[ntpd] => Package[ntp]; try using the '--graph' option
and open the '.dot' files in OmniGraffle or GraphViz

The result looks something like this:

In this simple example, it’s not hard to spot that the NTP package and service depend on each other, creating a cycle which you have to fix before Puppet will work. With dependency cycles involving many resources it can be a big help to see a diagram like this.

Of course, there are other uses for dependency graphs. As you develop Puppet manifests, from time to time you need to refactor them to make them cleaner, simpler, smaller and more modular, and looking at a diagram can be very helpful with this process. For one thing, it can help make it clear that some refactoring is needed: