3

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.

sethvargo
  • 26,739
  • 10
  • 86
  • 156

2 Answers2

4

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.

sethvargo
  • 26,739
  • 10
  • 86
  • 156
  • `node.set` was removed starting in Chef 14. In subsequent versions, you must explicitly set the precedence level, like `node.default`. Details are [here](https://docs.chef.io/deprecations_attributes.html#set-and-set-unless). – nofinator Aug 09 '19 at 18:05
  • dead link to attribute precedence levels: – Sheng Jiang 蒋晟 May 19 '20 at 17:34
1

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.

wondra
  • 11
  • 1