I have ‘default[‘apple’][‘size’][‘big’]’ and I want to update that as node[‘apple’][‘size’][‘small’] in a ‘ruby_block’ when converge.
Updating node object directly does not seem to be allowed. How can I solve that?
@Don Try the below ruby_block
, it should work.
ruby_block "setting up new attributes" do
block do
node.set['apple']['size']['small'] = "test"
end
action :run
end
@suthir , when I try what you said, I get this.
NoMethodError: undefined method `set' for #<Chef::Node::Attribute:0x0000000003ba8d28>
from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.2.0/lib/chef/node.rb:263:in `public_send'
‘set’ method for the node attribute is somehow undefined?
No idea what’s wrong…
I think I found a proper way.
I declare
default[‘apple’][‘size’] = 'big'
in attribute or policy file
and update it as follow.
node.force_default[‘apple’][‘size’] = 'small'
Cool
The node.set
has been removed with Chef 14. https://docs.chef.io/deprecations_attributes.html
Thank you @joerg.herzinger
thank you very much you all