我正在努力让厨师执行以下操作:
我知道你可以这样做:
remote_file "some remote file" do
...
not_if "apt-cache search 'mypackage'"
end
然而,我试过了:
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
这样做是否更简单,更不方便?
基本上,我最理想的是:
begin
package 'some-package-name' do
action :install
done
rescue Chef::Exception
# Do something here
end
答案 0 :(得分:8)
您可以使用ignore_failure true安装Debian软件包。然后,只有在此时未安装Debian软件包时才能安装pip软件包。这看起来像这样:
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