我正在开发一本食谱来部署一个简单的基于jekyll的博客。我使用'application'cookbook作为基础。一切顺利,但厨师只是忽略了我定义的回调。
Chef日志包含有关我的回调的条目,但我看不到回调执行的错误或结果。
这是recipes / default.rb文件:
include_recipe "git"
application "example_com" do
path "/var/www/example.com"
repository "git@example.org:xxx/xxx.git"
revision "master"
deploy_key <<EOF
-----BEGIN RSA PRIVATE KEY-----
..skip...
-----END RSA PRIVATE KEY-----
EOF
# before_symlink "script/bootstrap"
before_deploy do
# raise
# Chef::Log.info("INSANE!")
execute "bundle exec rake generate" do
cwd release_path
end
end
end
以下是chef-client表示执行before_deploy回调的日志:
[2012-10-06T10:06:20-04:00] INFO: Processing ruby_block[example_com before_deploy] action create (/var/cache/chef/cookbooks/application/providers/default.rb line 107)
[2012-10-06T10:06:20-04:00] DEBUG: Got callback before_deploy: #<Proc:0x00007f0509788088@/var/cache/chef/cookbooks/example_com/recipes/default.rb:24>
[2012-10-06T10:06:20-04:00] INFO: application[example_com] running callback before_deploy
[2012-10-06T10:06:20-04:00] INFO: ruby_block[example_com before_deploy] called
[2012-10-06T10:06:20-04:00] INFO: Processing deploy_revision[example_com] action deploy (/var/cache/chef/cookbooks/application/providers/default.rb line 122)
我也尝试使用string定义回调,但结果是一样的。当没有带回调定义的文件时,Chef会显示错误,如果文件位于正确的位置,则会忽略该文件。
更新1
在深入挖掘Chef内部消息后,我意识到回调是在单独的主厨中执行的,而这种情况不会立即发生。当应用程序cookbook中的代码调用_recipe_eval_来评估回调主体时,Chef会创建单独的运行程序,并且在调用 converge 方法之前代码不会执行。
所以,我稍微修改了应用程序的烹饪书。我在_recipe_eval_之后添加了调用 converge ,一切都开始工作了。
我认为这是一个错误,我将在官方Opscode跟踪器中创建一个问题。但是,非常欢迎任何评论!
这是application / libraries / default.rb的修改版本:
class Chef
class Provider
module ApplicationBase
# ...skip...
def callback(what, callback_code=nil)
Chef::Log.debug("Got callback #{what}: #{callback_code.inspect}")
@collection = Chef::ResourceCollection.new
case callback_code
when Proc
Chef::Log.info "#{@new_resource} running callback #{what}"
# recipe_eval(&callback_code)
recipe_eval(&callback_code)
converge # <--- Remove this line and no callbacks will work.
when String
callback_file = "#{release_path}/#{callback_code}"
unless ::File.exist?(callback_file)
raise RuntimeError, "Can't find your callback file #{callback_file}"
end
run_callback_from_file(callback_file)
when nil
nil
else
raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
end
end
end
end
end
答案 0 :(得分:1)
Opscode刚刚确认这是Chef的一个错误。如果有人需要更多详细信息和修复程序的状态,请使用以下链接: