我正在为厨师10写一个LWRP。 当该资源在其他配方中运行时,如果某些内容发生了变化,则应将其标记为“updated_by_last_action”。但如果没有任何改变。 updated_by_last_action应为false。
例如,我有厨师文档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?)
但是如果提供者变得更大并且使用了很多资源,比如模板,文件,目录,mount等。 是否应将所有这些资源包装在变量(如示例中)以查明资源是否已更新,以便进一步发送此提供程序已更新的状态。
我想知道是否有更简单,更清晰的方式来运行new_resource.updated_by_last_action(true)
,然后将所有资源包装在变量中。因为如果我在new_resource.updated_by_last_action(true)
action
之前将end
放在每个厨师运行时标记为更新的LWRP之内,这不是最佳的。
答案 0 :(得分:5)
您可以在LWRP的顶部添加use_inline_resources
,将updated_by_last_action
委托给内联资源。