首页 > 解决方案 > 如何在 CHEF 中为资源块的操作添加条件?

问题描述

我创建了一个具有两个操作的资源。

假设动作:A1 和动作:A2。我能够像这样在一个资源块(测试)中调用它们:

test 'Testing the actions' do
    action [:a1 ,:a2]
    only_if {::File.exists?"/tmp/action_exist.txt"}
end

它工作正常。但是如果我想在这样的动作上添加条件怎么办

检查条件仅用于操作:A1。并简单地运行 action :A2 而不管条件如何。

我试过这样:

test 'Testing the actions' do
    action [:A1 ,:A2]
    if (action.first=="A1")
            puts "yes"
            only_if {::File.exists?"/tmp/action_exist.txt" }
    end

结尾

但它不起作用。它正在为这两个动作执行此条件

标签: rubychef-infrachef-recipechef-solocookbook

解决方案


这不是厨师的工作方式。资源主体不是运行每个操作的脚本。


推荐阅读