Chef infra 如何在已完成时停止运行Chef Recipe

Chef infra 如何在已完成时停止运行Chef Recipe,chef-infra,vagrant,Chef Infra,Vagrant,我为安装phpunit的流浪者制作了一个配方,但是当我使用流浪者停止然后流浪者上升时,它一直失败 execute "discover phpunit" do command "pear channel-discover pear.phpunit.de" action :run end execute "config phpunit" do command "pear config-set auto_discover 1" action :run end execute "in

我为安装phpunit的流浪者制作了一个配方,但是当我使用流浪者停止然后流浪者上升时,它一直失败

execute "discover phpunit" do
  command "pear channel-discover pear.phpunit.de"
  action :run
end

execute "config phpunit" do
  command "pear config-set auto_discover 1"
  action :run
end

execute "install phpunit" do
  command "pear install pear.phpunit.de/PHPUnit"
  action :run
end
我得到:

[default] [Thu, 29 Mar 2012 14:39:57 -0700] ERROR: execute[discover phpunit] (phpunit::default line 39) has had an error
[Thu, 29 Mar 2012 14:39:57 -0700] ERROR: execute[discover phpunit] (/tmp/vagrant-chef-1/chef-solo-1/phpunit/recipes/default.rb:39:in `from_file') had an error:
execute[discover phpunit] (phpunit::default line 39) had an error: Chef::Exceptions::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of pear channel-discover pear.phpunit.de ----
STDOUT: Channel "pear.phpunit.de" is already initialized

看起来每次执行
vagrant up
时都会运行此脚本

你可能想要这样的东西:

execute "discover phpunit" do
  command "pear channel-discover pear.phpunit.de"
  action :run
  not_if "which phpunit"
end

只要确保
phpunit
在您的
$PATH

中,我可能会将not\u设置为

not_if { File.exists?('/path/to/phpunit')

而不是依赖于在$PATH中找到它。

您使用的是哪个版本的vagrant?没错。好的!这里还有一个问题:如果有phpunit,我怎么能让它退出食谱?@NathanBrakk(据我所知)真的没有办法“退出”一个食谱,因为它基本上是一个过程脚本。换句话说,让你的食谱幂等由你决定。