Hey everyone,
Another week comes to a close and with it more new Chef cops in Cookstyle. This time Cookstyle brings 11 new cops and some nice fixes.
Chef/UseInlineResourcesDefined
The UseInlineResourcesDefined
cop checks for resources that call the use_inline_resources
method. Chef Infra Client 13 made the inline resources mode as the default for all resources, so this call is no longer necessary.
Enabled by default
: True
Autocorrects
: Yes
Chef/IncludingOhaiDefaultRecipe
The IncludingOhaiDefaultRecipe
cop detects cookbooks that include the ohai::default
recipe. The ohai cookbook's default recipe was used to install custom Ohai plugins located in the cookbook's files
directory. Since the ohai cookbook required placing plugins into the cookbook's files
directory it had to be forked locally, which we no longer recommend doing. Modern versions of the Ohai cookbook provide an ohai_plugin resource, which can be used to install plugins into Chef Infra Client. Chef Infra Client will install also install Ohai plugins at runtime if they are placed in an /ohai
directory in any cookbook. Note: This feature requires Chef Infra Server 12.18 or later.
Enabled by default
: True
Autocorrects
: No
Chef/IncludingXMLRubyRecipe
The IncludingXMLRubyRecipe
cop detects cookbooks that include the xml::ruby
recipe. This recipe was used to install the nokogiri
gem into Chef Infra Client for use in parsing XML in cookbooks. Nokogori ships with Chef Infra Client 13+, so this recipe is no longer necessary.
Enabled by default
: True
Autocorrects
: Yes
Chef/LegacyYumCookbookRecipes
The LegacyYumCookbookRecipes
cop detects usage of legacy yum cookbook recipes. These recipes were removed from the yum cookbook in verson 3.0, which was released in 2013. Cookbooks should be updated to use the new individual yum cookbooks, which contain the same functionality as the legacy recipes.
Examples
Legacy recipes:
include_recipe 'yum::epel'
include_recipe 'yum::ius'
New cookbooks containing the same functionality:
include_recipe 'yum-epel'
include_recipe 'yum-ius'
Enabled by default
: True
Autocorrects
: No
Chef/DefaultMetadataMaintainer
The DefaultMetadataMaintainer
cop detects the default maintainer
and maintainer_email
fields generated by the chef generate cookbook
command. Cookbook metadata should be updated with actual maintainer information.
Enabled by default
: True
Autocorrects
: No
Chef/UsesDeprecatedMixins
The UsesDeprecatedMixins
cop detects various legacy mixins used in HWRP
and LWRP
resources. These mixins are no longer necessary and were removed in Chef Infra Client 14. Running these legacy mixins with HWRP
and LWRP
resources on modern Chef Infra Client releases will cause errors.
Enabled by default
: True
Autocorrects
: Yes
Chef/MinitestHandlerUsage
The MinitestHandlerUsage
cop detects cookbooks that depend on the minitest-handler cookbook. This cookbook provides a handler for running minitests after each Chef Infra Client run. The handler is no longer maintained and we highly recommend using InSpec for validating a system configuration after a Chef Infra Client run. InSpec includes over 100 built-in resources and integrates with Automate to report the results of a system state validation.
Enabled by default
: True
Autocorrects
: No
Chef/WindowsVersionHelper
The WindowsVersionHelper
cop detects the usage of the various Windows version helpers that shipped in the windows cookbook. Nearly all of the resources that originally shipped in the windows cookbook are now part of Chef Infra Client itself. We would like to help move users away from the windows cookbook so they can avoid the added dependency in their environment. Instead of using the Windows version helpers, we suggest using data from Ohai itself to determine what version of Windows is running on a node.
Examples
A cookbook using the Windows version helper:
Windows::VersionHelper.nt_version == 6.1
The same version comparison could be done using Ohai attributes
node['platform_version'].to_f == 6.1
Enabled by default
: True
Autocorrects
: No
Chef/WindowsZipfileUsage
The WindowsZipfileUsage
detects the usage of the windows_zipfile
resource in the windows cookbook. The windows_zipfile
resource is one of the remaining resources in the windows cookbook that is not present in Chef Infra Client itself. In Chef Infra Client 15.0, we introduced the archive_file resource, which is a cross-platform resource for uncompressing archives. This new resource uses an ultra-fast compression library with support for multiple compression formats, and should be used instead of the legacy windows_zipfile
resource.
Enabled by default
: True
Autocorrects
: No
Chef/NodeMethodsInsteadofAttributes
The NodeMethodsInsteadofAttributes
cop detects cookbooks that reference node attributes in the legacy node.some.value
format. Chef Infra Client 13 officially deprecated this attribute format. This cop detects the usage of common Ohai attributes and can autocorrect those. But it won't detect cookbook attributes which also need to be updated.
Enabled by default
: True
Autocorrects
: Yes
Examples
Node attributes in the method format:
node.platform
node.platform_version
node.my_cookbook.attribute1
The preferred format:
node['platform']
node['platform_version']
node['my_cookbook']['attribute1']
Chef/IncludingMixinShelloutInResources
The IncludingMixinShelloutInResources
cop detects resources that require and include the Chef Shellout Mixin helper. Chef Infra Client now includes the Chef Shellout Mixin helper automatically for all resources, so require and include statements can be removed from all resources.
Enabled by default
: True
Autocorrects
: Yes
Other fixes and changes
- Multiple cops will now skip scanning metadata.rb to speed up cookstyle runs
- Chef/MetadataMissingName now supports autocorrecting. The folder containing the metadata.rb will be used as the cookbook name if it's missing from metdata.rb
- Chef/WhyRunSupportedTrue has been corrected to properly trigger on the whyrun_supported method in resources
- The files directory in cookbooks is now excluded from Cookstyle scans
Enoy,
Tim