【发布时间】:2014-03-09 07:31:19
【问题描述】:
我正在为厨师 10 编写 LWRP。 并且当该资源在其他配方中运行时,如果发生更改,则应将其标记为“updated_by_last_action”。但如果一切都没有改变。 updated_by_last_action 应该是假的。
例如,我有厨师文档http://docs.opscode.com/lwrp_custom_provider.html#updated-by-last-action。该示例将资源模板包装在一个变量中以测试它是否已更改,然后设置 updated_by_last_action 状态。 所以我的代码应该是这样的
f = file new_resource.filename do
xxx
end
new_resource.updated_by_last_action(f.updated_by_last_action?)
t = template new_resource.templatename do
xxx
end
new_resource.updated_by_last_action(t.updated_by_last_action?)
m mount new_resource.mountpoint do
xxx
end
new_resource.updated_by_last_action(m.updated_by_last_action?)
但如果提供者变得更大并使用大量资源,如模板、文件、目录、挂载等。 所有这些资源是否应该像示例一样包含在变量中以查明资源是否已更新,以便进一步发送此提供程序已更新的状态。
我想知道是否有一种更简单、更简洁的方式来运行new_resource.updated_by_last_action(true),然后将所有资源包装在变量中。因为如果我只是在end 之前将new_resource.updated_by_last_action(true) 放在action 中,LWRP 会被标记为每次厨师运行时都会更新,这不是最佳的。
【问题讨论】:
标签: ruby chef-infra lwrp