gpt4 book ai didi

ruby - Chef Recipe lwrp,使用 new_resource.updated_by_last_action(true) 的最简单方法

转载 作者:数据小太阳 更新时间:2023-10-29 07:52:52 26 4
gpt4 key购买 nike

我正在为 10 号 Chef 编写 LWRP。当该资源在其他配方中运行时,如果某些内容已更改,则应将其标记为“updated_by_last_action”。但如果一切都没有改变。 updated_by_last_action 应该是假的。

例如,我有 Chef 文档 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 将被标记为在每次 Chef 运行时更新,这是不是最优的。

最佳答案

您可以在 LWRP 的顶部添加 use_inline_resources,这会将 updated_by_last_action 委托(delegate)给内联资源。

关于ruby - Chef Recipe lwrp,使用 new_resource.updated_by_last_action(true) 的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21703112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com