Reputation: 24959
I'm trying to get Chef to perform the following:
I know you can do:
remote_file "some remote file" do
...
not_if "apt-cache search 'mypackage'"
end
However, I tried:
ruby_block "Attempting to install #{node[:bact][:application_name]}" do
block do
cmd = Chef::ShellOut.new("apt-get install -y --force-yes #{node[:bact][:application_name]}")
exec_result = cmd.run_command
if exec_result.exitstatus != 0
Chef::Log.info 'Go grab some coffee, this might be a while....'
resources("execute[install-#{node[:bact][:application_name]}-via-pip]").run_action(:run)
end
end
action :create
end
Is there an easier and less uglier way to do this?
Basically, what I'd ideally like to do is:
begin
package 'some-package-name' do
action :install
done
rescue Chef::Exception
# Do something here
end
Upvotes: 3
Views: 8766
Reputation: 55803
You could install the Debian package using ignore_failure true. Then you can install the pip package only if the Debian package is not installed at this point. This could look something like this:
package node[:bact][:application_name] do
ignore_failure true
end
# Resource available from the opscode python cookbook
python_pip node[:bact][:application_name] do
# Install the pip package only if the debian package is not installed
not_if "dpkg-query -W '#{node[:bact][:application_name]}'"
end
Upvotes: 8