Skip to main content

ConditionalRubyShellout

All Cookstyle Cops


The department is: Chef/Correctness

The full name of the cop is: Chef/Correctness/ConditionalRubyShellout


Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

Don’t use Ruby to shellout in a only_if / not_if conditional when you can just shellout directly. Any string value used with only_if / not_if is executed in your system’s shell and the return code of the command is the result for the not_if / only_if determination.

Examples

incorrect

cookbook_file '/logs/foo/error.log' do
  source 'error.log'
  only_if { system('wget https://www.bar.com/foobar.txt -O /dev/null') }
end

cookbook_file '/logs/foo/error.log' do
  source 'error.log'
  only_if { shell_out('wget https://www.bar.com/foobar.txt -O /dev/null').exitstatus == 0 }
end

correct

cookbook_file '/logs/foo/error.log' do
  source 'error.log'
  only_if 'wget https://www.bar.com/foobar.txt -O /dev/null'
end

Configurable attributes

NameDefault valueConfigurable values
Version Added6.1.0String
Exclude
  • **/attributes/*.rb
  • **/metadata.rb
  • **/Berksfile
Array

Was this page helpful?