Let\'s say I have a default attribute in a cookbook:
default.nginx_upstreams = {
\'service1\' => [\'service1.server.com\'],
\'service2\' => [\'
default.nginx_upstreams is the same as default[:nginx_upstreams] and default['nginx_upstreams'] - the convention is to use 1 of the latter two. And as you are using strings further, use them here too.
The way you init nginx_upstreams in attribute file is the same as doing it this way:
default['nginx_upstreams']['service1'] = ['service1.server.com']
default['nginx_upstreams']['service2'] = ['service2.server.com']
And you don't have to init default['nginx_upstreams'] = {} before that. These are not hashes, but attributes, and they are a lot smarter. :)
Modifying attributes from inside the recipe is done like that:
node.default['nginx_upstreams']['service3'] = ['service3.server.com']
You can use set or override instead of default here, if you need to change precedence. Omitting the precedence name (node['nginx_upstreams'] or node.nginx_upstreams) will use the set precedence. But this is deprecated and soon to be removed - that's what the warning is all about.
Check out the manual page about attributes, because everything is actually there.
So after digging around, I found the answer:
node.set
Use node.default (or maybe node.override) instead of node.set because node.set is an alias for node.normal. Normal data is persisted on the node object. Therefore, using node.set will persist data in the node object. If the code that uses node.set is later removed, if that data has already been set on the node, it will remain.
Normal and override attributes are cleared at the start of the chef-client run, and are then rebuilt as part of the run based on the code in the cookbooks and recipes at that time.
node.set (and node.normal) should only be used to do something like generate a password for a database on the first chef-client run, after which it’s remembered (instead of persisted). Even this case should be avoided, as using a data bag is the recommended way to store this type of data.
Just wanted to give further insight on Chef attributes, it is very important for users, who is going to refer this question on node attribute override.
File Methods corresponds to attributes
Use the following methods within the attributes file for a cookbook or within a recipe. These methods correspond to the attribute type of the same name:
Attribute Precedence
Attributes are always applied by the chef-client in the following order:
where the last attribute in the list is the one that is applied to the node.
It means that, OHAI attribute will have the highest precedence, where as the default attribute in cookbook attribute file will have the lowest precedence.
Note: Provided the important details from Chef docs for attributes for the benefit of users. Because sometimes the URL will be moved or invalid.