Deprecation: Some Attribute Methods (CHEF-4)

[edit on GitHub]

We are continuously improving and streamlining the way attributes work in Chef, to make it easier for users to reason about and safely configure their servers.

This page documents many deprecations over the course of many Chef releases.

Method Access

Setting and accessing node attributes has been standardized on “bracket” syntax. The older “method” syntax is deprecated and will be removed in Chef Client 13.

Removal: Chef Client 13

Example

Both lines in the example will cause separate deprecation warnings.

node.chef.server = 'https://my.chef.server'
chef_server = node.chef.server

Remediation

Convert method syntax to bracket syntax by using brackets to denote attribute names. The code below is identical in function to the example above:

node['chef']['server'] = 'https://my.chef.server'
chef_server = node['chef']['server']

Set and Set_Unless

Setting node attributes with set or set_unless has been deprecated in favor of explicitly setting the precedence level. These methods will be removed in Chef Client 14.

Removal: Chef Client 14

Example

node.set['chef']['server'] = 'https://my.chef.server'
node.set_unless['chef']['server'] = 'https://my.chef.server'

Remediation

Choose the appropriate precedence level, then replace set with that precedence level.

node.default['chef']['server'] =  'https://my.chef.server'
node.default_unless['chef']['server'] = 'https://my.chef.server'

© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/deprecations_attributes/