厨师cookbook lwrp,最简单的方法使用new_resource.updated_by_last_action(true)

Rab*_*boo 3 ruby chef-infra lwrp

我正在为厨师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?)
Run Code Online (Sandbox Code Playgroud)

但是如果一个提供者变得更大并且使用了很多资源,比如模板,文件,目录,mount等等.应该将所有这些资源包装在像示例这样的变量中,以找出资源是否已经更新,以便进一步发送此提供程序已更新的状态.

我想知道是否有一种更简单,更清晰的方式来运行new_resource.updated_by_last_action(true)其他,然后将所有资源包装在变量中.因为如果我在每次厨师运行时将LWRP标记为更新之前放入new_resource.updated_by_last_action(true)内部,这不是最佳选择.actionend

set*_*rgo 5

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