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.
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
If it actually is okay for the package to not be installed and the rest of
the Chef run can be finished without issue, then you can use the
ignore_failure parameter.
package pkg do
ignore_failure true
action :install
end
It's available to any resource, like notifies, subscribes, etc. Use this
parameter sparingly though.
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
If it actually is okay for the package to not be installed and the rest of
the Chef run can be finished without issue, then you can use the
ignore_failure parameter.
package pkg do
ignore_failure true
action :install
end
It's available to any resource, like notifies, subscribes, etc. Use this
parameter sparingly though.
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:
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.