Skip to main content

Chef/Style/SimplifyPlatformMajorVersionCheck

Cookstyle cops page

The Cookstyle cops department: Chef/Style

Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

When checking the major version number of a platform you can take the node[‘platform_version’] attribute and transform it to an integer to strip it down to just the major version number. This simple way of determining the major version number of a platform should be used instead of splitting the platform into multiple fields with ‘.’ as the delimiter.

Examples

incorrect

node['platform_version'].split('.').first
node['platform_version'].split('.')[0]
node['platform_version'].split('.').first.to_i
node['platform_version'].split('.')[0].to_i

correct


# check to see if we're on RHEL 7 on a RHEL 7.6 node where node['platform_version] is 7.6.1810
if node['platform_version'].to_i == 7
  # some code
end

Configurable attributes

NameDefault valueConfigurable values
Version Added5.8.0String
Include
    Array

    Thank you for your feedback!

    ×









    Search Results