我有以下食谱(食谱/ master.rb):
master do
action :install
end
使用定义(definitions / master.rb)
define :master, :action => nothing do
[...]
if params[:action] == :install and not master_installed?(master_path)
#install master code here - above you can see first call of "master_installed?"
end
[...]
if master_installed?(master_path)
#do something if master has been installed
end
end
使用帮助程序库" master_installed?"指定了函数:
module Opscode
module MyHelpers
[...]
def master_installed?(path)
cmd = shell_out("test -f #{path}/bin/startup_linux.bash")
if (cmd.exitstatus == 0 and cmd.stderr.empty?)
return true
else
return false
end
end
end
end
所以我使用" master_installed?"在运行时运行两次。在未安装master的初始运行时,应调用两次,方案应该如下:
master_installed? => False
(在master.rb中首次调用)master_installed? => True
(在master.rb中第二次调用)但实际上是master_installed?似乎只在评估时评估一次,所以它看起来像:
master_installed? => False
(在master.rb中首次调用)master_installed? => False
(在master.rb中第二次调用)所以我必须两次运行chef-client,因为: