0

I am just trying to understand if there is a difference on how we define the attribute structure in the cookbook's attribute files.

Following are two examples:

// style-A
default['my_cookbook']['name'] = 'something'
default['my_cookbook']['version'] = '0.1.0'

// style-B
node.default.my_cookbook = {
  :name => 'something',
  :version => '0.1.0'
}

The reason I am asking this question is, in the previous versions of chef I kind of remember style-A is highly recommended and all the community cookbooks follow this style. I also recall seeing some issues with the style-B when I used to try to override the attributes from role or environment I would come up with a weird behavior that replaces the whole hash structure if I tried to override a single attribute in it.

I am not seeing this error now and I am on the latest 11 version of chef but was just wondering if this is something I should worry about. I am trying to be consistent with all my cookbooks with a single style and I need some advice on how I structure it. Does it matter at this point?

4

1 回答 1

1

使用default['key']['subkey']样式时,defaultis aMash[]=Mash 的方法会将Hash哈希数组或哈希数组转换为 Mash。

node.default.property =样式将分配 aHash而无需调用该[]=方法。

Mash 继承自 Hash 提供额外的功能,以及覆盖初始化器的默认值,{}使任何未定义的值成为哈希,然后由于 mash 的行为将其转换为 mash。

于 2016-09-14T20:16:43.443 回答