# Merging Hashes

**URL:** <https://discourse.chef.io/t/merging-hashes/3853>\
**Category:** Chef Infra (archive)\
**Created:** [April 17, 2013, 9:27pm UTC](https://discourse.chef.io/t/merging-hashes/3853 "2013-04-17T21:27:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Pimentel](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@Mark\_Pimentel](https://discourse.chef.io/u/Mark_Pimentel)\
**Post date:** [April 17, 2013, 9:27pm UTC](https://discourse.chef.io/t/merging-hashes/3853/1 "2013-04-17T21:27:29Z")

</div>

Just wondering if anyone could help with merging of hashes.

I am attempting to take a given node object and copy it to a hash:

vars = node.test.to\_hash

Then I have a data bag with similar keys/values as the node.test object.

{  
“id”: “mydbag”,  
“default”: {  
“var1”: “value1”,  
“var2”: “value2”  
}  
}

So the default in attributes for node.test.var1 = "value\_1"  
And the data bag is var1 =\> value1

I want to be able to vars.deep\_merge!(dbag[“default”]) but every time I try Chef throws

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”’

vars.class returns Hash as expected and not a node object so why the Exception?

Any way around this?
