ruby - 如何在 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
结尾
但它不起作用。它正在为这两个动作执行此条件
解决方案
这不是厨师的工作方式。资源主体不是运行每个操作的脚本。
推荐阅读
- windows - 通过bat文件检查进程是否挂起
- java - 如何向 Google 的 Guice Provider 提供参数?
- sql - 用排名合并行
- c - 为什么编译器在这里坚持使用被调用者保存的寄存器?
- scala - 从 ZIO (Scala) 获取 ZManaged 的类型转换
- google-analytics - PII 数据作为自定义维度提供给 Google Analytics
- user-interface - 如何创建一个玩家必须猜测随机生成的 pin 的 Roblox 游戏?
- typescript - Vue / Express Cors 问题
- python - 从同一个类中获取两个移动对象进行交互(pygame)
- python - 如何在 Python 中使用 rdkit 确定任何分子的链烷烃 CH3、CH2 和 CH 基团的数量?