[chef] Re: Can't rescue from a 'package' resource call


Chronological Thread 
  • From: Lamont Granquist < >
  • To: < >
  • Subject: [chef] Re: Can't rescue from a 'package' resource call
  • Date: Mon, 26 Nov 2012 12:28:03 -0800


Chef evaluates cookbooks in two (major) phases.  The first phase is "compile phase" where everything gets run through the ruby interpreter and resources are placed on the resource collection.  The second phase is the convergence of the resource collection where the chef resources do their work.  What you're doing there is trying to catch exceptions throw when the package resource is put onto the resource collection (which would only be things like attributes failing validation or internal chef errors of some kind), not when the package resource is later evaluated.

On 11/25/12 3:37 PM, Marcelo de Moraes Serpa wrote:
" type="cite"> Hi list,

I'm trying to ignore the Chef::Exceptions::Package exception from breaking the cook process by wrapping the package method call in a begin;rescue, and rescuing from the Chef::Exceptions::Package exception, but even so, when the package is not present, it just breaks. Am I doing anything wrong? Here's the code:

%w( wget zlib1g-dev libssl-dev libffi-dev libxml2-dev libncurses5-dev libreadline5-dev libreadline-dev ).each do |pkg|
  begin
    package pkg do
      action :install
    end
  rescue Chef::Exceptions::Package => e
    Chef::Log "Could not install #{pkg}"
  end
end

In this specific scenario, the ubuntu VM I'm cooking on doesn't have the libreadline5-dev, and I just want to ignore it and make it try the libreadline-dev instead.

Thanks,

- Marcelo.




Archive powered by MHonArc 2.6.16.

§