Tuesday, February 17, 2015

Chef Runtime Error Nil:NilClass

Today, an error came up with our Chef environment. The chef-client on new servers was having NoMethodError responses and failing during the chef-client run. 



The problem

The error message was pointing at a particular piece of code that has not given us trouble in the past. That code would look like the code below.

variables({
    :attribute_one => node[:node][:attribute][:one],
    :attribute_two => node[:node][:attribute][:two]
})

Fun fact, in Chef Client 12 the notation above no longer works. This is what is cause the nil:NilClass error. The node[:node][:attribute] values are being resolved to nil. That nil value is then stored in the :attribute_one and :attribute_two which means the value ends as a null method.

The fix

variables({
    :attribute_one => node['node']['attribute']['one'],
    :attribute_two => node['node']['attribute']['two']
})

No comments:

Post a Comment