wr0ngway/rubber — Issue #119: Method for first hostname for a given role
Author: akremer
Created: 2012-02-06 18:08:36+00:00
State: open

If you vulcanize graphite and collectd in the same project (something which is done by default with complete_passenger_postgres), graphite puts a config file for collectd into role/collectd called graphite-collectd.conf. This seems fine until you add the collectd role to an instance but not graphite. Then rubber:config fails due to the transformation of that config file which contains the following:

rubber_instances.for_role('graphite_server').first.full_name

Since there is no graphite_server, it crashes trying to do nil.first.full_name.

A bunch of other templates have this issue as well, specifically the ones that run rubber.run_config during bootstrap to get config files in place. If you've vulcanized for a few roles but haven't created an instance for all of them, you're very likely to run into this issue as well.

This could be easily fixed with a "rescue" but I think there should be a better way to deal with this… Perhaps a helper method that returns the first full hostname for a given role, else ""? Or maybe more elegantly deal with config files that depend on other roles: Don't transform them if the dependent role hasn't been configured in the project. Any thoughts?