[chef] Re: Exception handling for the Execute Resource

Chronological Thread 
  • From: Max Gorbul < >
  • To:
  • Subject: [chef] Re: Exception handling for the Execute Resource
  • Date: Thu, 19 Apr 2012 15:27:09 -0700

you can run execute resource right here and catch the exception as usual

  execute "foo" do
     action :nothing
rescue  Mixlib::Shellout::ShelloutCommandFailed => e
   puts "Exception is here #{e}"

or you can add other then "0" status codes to the "returns" option

execute "foo" do
   returns [0, 255, 1, 2, 3]

Thank you,

On Thu, Apr 19, 2012 at 3:17 PM, Carl Perry < "> > wrote:

I've got a situation where I'm iterating through a list and performing
operations on them.  One of these operations looks like this:

   execute "Format data device for #{osd_id} using XFS" do
     command "mkfs.xfs -f #{mkfs_opts} -L osd.#{osd_device['osd_id']}

What I would like to do is instead of aborting the entire chef run
because this failed, and instead mark it failed and move on to the next
one.  What is the best practice for catching an exception from an
execute resource and taking action instead of aborting?



Archive powered by MHonArc 2.6.16.