Skip navigation.

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:

Thanks, I was just about to

Thanks, I was just about to tweet something similar before I found your post to make my need go away. :-)

Automatic dependency finding

This has really helped me a number of times. However, for a number of nodes, the graphs were so full of dozens of classes it was almost impossible to trace. If it’s helpful for anyone else, I whipped up a Python script (using the python graphviz and networkx packages) that uses the NetworkX package to programmatically detect cycles in the .dot graph files. For nodes with lots of classes/resources, it really comes in handy. The full description and link to source is at:…

Very nice! Thank you.

Very nice! Thank you.

Post new comment

The content of this field is kept private and will not be shown publicly.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.
By submitting this form, you accept the Mollom privacy policy.