Updating attributes in 0.7.6


#1

When I updated to chef 0.7.6 this morning, I had an issue with my
attributes (as noted in CHEF-473), causing this error:

/var/chef/cache/cookbooks/portage/definitions/keyword.rb:11:in `+’:
can’t convert Chef::Node::Attribute into String (TypeError)

This was because I had attribute code that looked like this:

cluster = Mash.new unless attribute?(“cluster”)
cluster[:ruby_version] ||= “1.8.7_p74”

This worked before 0.7.6, but with the new code in 0.7.6, a new
attribute is no longer initially nil, but an instance of
Chef::Node::Attribute. Thus, this value wasn’t being set properly.

The fix is to use the normal chef nomenclature…either the new, or the
old:

cluster[:ruby_version] = “1.8.7_p74” unless
cluster.has_key? :ruby_version

or

set_unless[:cluster][:ruby_version] = “1.8.7_p74”

I’m documenting this here in case anyone else runs into the issue, as
fixing the code in chef itself is non-trivial.

Thanks,
Caleb


#2

On Sat, Aug 8, 2009 at 11:00 AM, Caleb Tenniscaleb.tennis@gmail.com wrote:

When I updated to chef 0.7.6 this morning, I had an issue with my attributes
(as noted in CHEF-473), causing this error:
/var/chef/cache/cookbooks/portage/definitions/keyword.rb:11:in `+’: can’t
convert Chef::Node::Attribute into String (TypeError)
This was because I had attribute code that looked like this:
cluster = Mash.new unless attribute?(“cluster”)
cluster[:ruby_version] ||= “1.8.7_p74”

Caleb rocks for finding this bug and working with me to fix it. This
only occurs when you use ||= to set a value. The fix is in my
adamhjk/chef-473 branch, and we’ll get it integrated with the mainline
chef and cut a new release with this fix in it on Monday. If you have
lots of ||=, you may want to hold off until then.

(Or just switch over to the new attribute sauce, because it is much
nicer anyway.)

Regards,
Adam


Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com