Hello,
If i use chef-client --local-mode (11.14.2) with my recipe, where i have
default hash attribute like a = {“default”: “1”} and try use a role with
override_attributes section where a = {“no-default”: “2”} i get result a =
{“default”: “1”, “no-default”: “2”}.
I know that if a determine a default attribute in role it will be merge, but i
think that if i write my attributes in “override_attributes” section that will
be overriding. What i do wrong?
On Friday, August 22, 2014 at 6:38 AM, dmitry.r@cyberflow.net wrote:
Hello,
If i use chef-client --local-mode (11.14.2) with my recipe, where i have
default hash attribute like a = {"default": "1"} and try use a role with
override_attributes section where a = {"no-default": "2"} i get result a =
{"default": "1", "no-default": "2"}.
I know that if a determine a default attribute in role it will be merge, but i
think that if i write my attributes in "override_attributes" section that will
be overriding. What i do wrong?
The Hashes are deep merged, which means any key in the override attributes will win over the exact same key in default attributes, but a key that appears in default attributes but not in override attributes will be untouched. Deep merge is just a more sophisticated version of the built-in merge
method, so you can play with that in irb or pry to get a feel for how it works:
[1] pry(main)> a = {"key1" => "value1", "key2" => "value2" }
=> {"key1"=>"value1", "key2"=>"value2"}
[2] pry(main)> b = { "key2" => "override value 2" }
=> {"key2"=>"override value 2"}
[3] pry(main)> merged = a.merge(b)
=> {"key1"=>"value1", "key2"=>"override value 2"}
--
Daniel DeLeo