Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using modified opsworks deploy cookbook immutable object error

I'm attempting to add some custom code into the opsworks deploy cookbook, related to the before_migrate step:

before_migrate do
  link_tempfiles_to_current_release
  deploy_version = Time.now.strftime("%Y%m%d%H%M%S")

  if node['deploy_app'] == 'web'
    link "/var/lib/tomcat#{node["tomcat"]["base_version"]}/webapps/ROOT###{deploy_version}" do
      to "#{release_path}"
    end

The issue I'm having is when I include the deploy cookbook in my site-cookbook package, I get a chef error:

[2013-08-27T16:45:05+00:00] FATAL: Chef::Exceptions::ImmutableAttributeModification:   ruby_block[Compile Custom OpsWorks Run List] (opsworks_custom_cookbooks::execute line 3) had an error: Chef::Exceptions::ImmutableAttributeModification: Node attributes are read-only when you do not specify which precedence level to set. To set an attribute use code like `node.default["key"] = "value"'

I've verified none of my cookbooks have incorrect node settings, so I'm out of ideas of what the issue could be. I'm finding this error very difficult to debug, and even when I include this cookbook without any modifications, I get this error. Please let me know if you can point me in the right direction.

like image 821
user2390053 Avatar asked Jun 06 '26 13:06

user2390053


2 Answers

As of Chef 11, attribute must specify a precedence level. In Chef 10, you could do something like this:

node['foo']['bar'] = 'my new value'

In Chef 11, you must specify the precedence level for that value:

node.set['foo']['bar'] = 'my new value'

You can also use default and override (which correspond to the attribute precedence levels:

node.default['foo']['bar'] = 'my new value'
node.override['foo']['bar'] = 'my new value'

I suspect the cookbook you are using (or a dependent cookbook) is setting data on the node object using the deprecated syntax.

like image 186
sethvargo Avatar answered Jun 09 '26 09:06

sethvargo


In Chef, attributes have several precedence values, most often used are probably default and override. http://docs.opscode.com/chef_overview_attributes.html You have to find where you are setting an attribute by specifying only node['something']. It doesn;t seem to be in the code you pasted.

like image 39
wondra Avatar answered Jun 09 '26 09:06

wondra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!