edelight/chef-cookbooks — Issue #21: members.sort! fails because of nil value
Author: ctgswallow
Created: 2011-12-15 14:08:26+00:00
State: open

When I try to configure a three-node replicaset I run into this error:

NoMethodError: ruby_block[config_replicaset] (mongodb::replicaset line 146) had an error: NoMethodError: undefined method `<=>' for nil:NilClass
/var/chef/cache/cookbooks/mongodb/libraries/mongodb.rb:45:in `configure_replicaset'
/var/chef/cache/cookbooks/mongodb/libraries/mongodb.rb:45:in `sort!'
/var/chef/cache/cookbooks/mongodb/libraries/mongodb.rb:45:in `configure_replicaset'
/var/chef/cache/cookbooks/mongodb/definitions/mongodb.rb:152

I added this to libraries/mongodb, which is why the stack trace says line 45, rather than line 42:

members.each do |m|
Chef::Log.error "configure_replicaset member name is #{m.name}"
end

Logs come out correctly.

mongo3 [Thu, 15 Dec 2011 13:57:26 +0000] ERROR: configure_replicaset member name is mongo2.me.com
mongo3 [Thu, 15 Dec 2011 13:57:26 +0000] ERROR: configure_replicaset member name is mongo3.me.com
mongo3 [Thu, 15 Dec 2011 13:57:26 +0000] ERROR: configure_replicaset member name is mongo1.me.com

But this fails:

members.sort!{ |x,y| x['name'] <=> y['name'] }