As you probably know if you work with Chef, Chef Client 13 was released a few weeks back. It features a number of enhancements aimed at making automation of your infrastructure more efficient. But it’s not backward compatible with Chef Client 12. This post is meant to help you size up the breaking changes and their impact on your Chef code.

Based on our experience, as well as guidance on the Chef Blog, the best way to start your Chef 13 upgrade is to move to Chef Client 12.19, the latest version of Chef 12. Chef will then report all the deprecations and compatibility issues in your Chef code that will become errors in Chef 13, along with links to the Chef documentation.

A list of breaking changes (which we’ve come to find is not complete) is available here. The biggest issues for many Chef users are likely to be these:

With the latest versions of Chef 12, it is recommended to run Ruby 2.2.2 or higher. Chef 13 runs on Ruby 2.4. This is mainly an issue for libraries or cookbooks that use Heavy Weight Resource Providers (HWRPs) or a lot of Ruby code.


Resource cloning has been removed in Chef 13.

Error: the same resource is declared twice

file '/etc/my_file' do
  owner 'ken'
end

file '/etc/my_file' do
  mode '0755'
end

Fix: de-duplicate your resource

file '/etc/my_file' do
  owner 'ken'
  mode '0755'
end

Hacky Fix: use this workaround where it’s difficult to de-duplicate your resources

# cookbook1/recipes/default.rb
file 'my_file1' do
  path '/etc/my_file'
  owner 'ken'
end

# cookbook2/recipes/default.rb
file 'my_file2' do
  path '/etc/my_file'
  mode '0755'
end

While it was always considered a “usage mistake,” using the command property on any script resource is now a hard error.

Error: 

bash 'flush postfix queue' do
  command 'postfix -f
end

Fix:

bash 'flush postfix queue' do
  code 'postfix -f'
end

Ohai now reports Amazon Linux as its own platform_family, as opposed to RHEL.

Error:

case node['platform_family']
when 'rhel'
  default['nginx']['user'] = 'nginx'
else
  default['nginx']['user'] = 'www-data'
end

Fix:

case node['platform_family']
when 'rhel', 'amazon'
  default['nginx']['user'] = 'nginx'
else
  default['nginx']['user'] = 'www-data'
end

Method access to node attributes (node.foo.bar) is deprecated and will be removed in Chef 13. Instead, use bracket syntax (node["foo"]["bar"]).

Error:

template '/etc/elasticsearch/elasticsearch.yml' do
  source 'elasticsearch.yml.erb'
  owner node.elasticsearch.user
end

Fix:

template '/etc/elasticsearch/elasticsearch.yml' do
  source 'elasticsearch.yml.erb'
  owner node['elasticsearch']['user']
end

If you feel your team might benefit from Chef consulting, Chef training or other guidance on any aspect of Chef or “infrastructure as code,” contact Bitlancer. We’re a Boston DevOps consulting firm focused on mentoring our clients and helping them build teams.

For more information: