In the hopes that it may be as useful to someone else as it was to me:

I wrote up a simple little Python script that uses the NetworkX package (http://networkx.lanl.gov/) and Pydot (http://code.google.com/p/pydot/) to automatically identify cycles in the .dot graph files produced by Puppet (when run with --graph or "graph = true"). It takes the name of a dot file (expanded_relationships.dot will probably be the best) and prints on stdout any cycles found in the graph, as lists of nodes, one cycle per line.

For the one complex dependency cycle that prompted me to write this (the "Could not apply complete catalog: Found dependency cycles in the following relationships:" error listed a chain of 35 relationships), one run of this script allowed me to identify the common resource that was causing the loop, and gave me a pretty good idea of where it was defined (going by what the dependencies looked like). It would've been pretty difficult to do this in the 14000x500px PNG generated by dot.

For the expanded_relationships.dot input (with 99 nodes), it gives output something like:

['File[foreman-report.rb]', 'File[puppet.conf]', 'Service[puppet]', 'File[foreman-report.rb]'] ['Package[puppet-server]', 'File[puppet.conf]', 'Service[puppet]', 'File[foreman-proxy-settings.yml]', 'Service[foreman-proxy]', 'Package[puppet-server]'] ['Package[puppet-server]', 'File[puppet.conf]', 'Service[puppet]', 'Package[foreman-proxy]', 'File[foreman-proxy-settings.yml]', 'Package[puppet-server]'] ['Package[puppet-server]', 'File[puppet.conf]', 'Service[puppet]', 'File[/var/lib/puppet/yaml/foreman]', 'Package[puppet-server]'] ['File[/etc/puppet/node.rb]', 'File[puppet.conf]', 'Service[puppet]', 'File[/etc/puppet/node.rb]'] ['File[puppet.conf]', 'Service[puppet]', 'File[foreman-proxy-settings.yml]', 'Service[foreman-proxy]', 'File[puppet.conf]'] ['File[puppet.conf]', 'Service[puppet]', 'User[foreman-proxy]', 'File[puppet.conf]']
... snip ...

The script itself, link to SVN, notes on using it, etc. are at:
http://blog.jasonantman.com/2012/03/python-script-to-find-dependency-cycles-in-graphviz-dot-files/

I've only run on Fedora/CentOS, but those only needed python, plus the python-networkx, graphviz-python, and pydot packages.

Hope it's useful to someone else as well.

-Jason Antman

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to