Anna
Anna

Reputation: 5

only if chef code fails , error should be captured by ignore_failure_true and display error message

execute 'install_insatller' do
  cwd "abc"
  command reg_cmd
  ignore_failure true
  log 'STDERROR'
  only_if { ::File.exist?('abc') }
end

this is just an expample code I want to print the log message only if the failure occurs else continue the installation.

Upvotes: 0

Views: 271

Answers (2)

Ambareesh V
Ambareesh V

Reputation: 86

If you want to capture output and take decission based on that then please use Mixlib shellout instead of execute.

if ::File.exist?('abc') require 'mixlib/shellout' cmnd = Mixlib::ShellOut.new(reg_cmd) cmnd.run_command if cmnd.error? puts cmnd.stderr else <write your code here to continue with installation> end end

Upvotes: 1

coderanger
coderanger

Reputation: 54211

ignore_failure true means that if there is an error, we show the usual error display but don't abort the converge. If you want behavior other than that, you'll probably have to write something yourself.

Upvotes: 1

Related Questions