对于调用任何配方,使用"include_recipe"方法。我创建了一个异常处理程序,在其中调用回滚配方。然而,这并不奏效。下面是我的代码:
require 'chef/log'
require 'time'
module TEST
class ExceptionHandler < Chef::Handler
def report
if run_status.failed? then
Chef::Log.info("Running Report handler for failed client run...")
Chef::Log.info("Formatted Exception: "+run_status.formatted_exception)
//here i want to call rollback recipe
include_recipe "TEST::rollback"
else
Chef::Log.info("Running success...")
end
end
end
end
日志文件包含如下内容:
- "运行失败的客户端报告处理程序"
- "格式化的例外"
但是,我没有在日志文件中找到提到回滚配方的任何内容。
我上面用来调用配方的代码是正确的吗?
调用处理程序时,Chef已经完成了它的执行。您必须为此创建一个自定义执行上下文。查看poise食谱及其include_recipe的实现,了解如何做到这一点,但我强烈建议不要这样做,因为所涉及的复杂性和结果系统将多么脆弱。