3

我正在为厨师 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)其他方法,然后将所有资源包装在变量中。因为如果我只是在 LWRP 被标记为在每次厨师运行时更新之前放入一个new_resource.updated_by_last_action(true)内部,这不是最佳的。actionend

4

1 回答 1

5

您可以use_inline_resources在 LWRP 的顶部添加,它将委派updated_by_last_action给内联资源。

于 2014-02-11T17:37:08.250 回答