gpt4 book ai didi

chef-infra - Chef : Use library function in attributes

转载 作者:行者123 更新时间:2023-12-04 13:49:46 26 4
gpt4 key购买 nike

如何在说明书的属性文件中访问自己的库函数(在以下模块中创建)?

module Gerrit
module Helpers
def gerrit_above?(version)
require 'chef/version_constraint'
Chef::VersionConstraint.new(">= #{version}").include?(node['gerrit']['version'])
end
end
end

Chef::Recipe.send(:include, ::Gerrit::Helpers)
Chef::Resource.send(:include, ::Gerrit::Helpers)
Chef::Provider.send(:include, ::Gerrit::Helpers)

我可以通过 gerrit_above? 在 Recipe 中访问它,但没有找到同时在属性文件中使用它的方法。我尝试了以下行
Chef::Node::Attribute.send(:include, ::Gerrit::Helpers)

但是在访问 node 时失败了和:
Undefined method or attribute `node' on `node'

有人有干净的解决方案吗?

最佳答案

我建议使用 node.run_state对象来存储资源和配方之间的 transient 数据。在此处查看更多信息:https://docs.chef.io/recipes/#noderun_state
如果您绝对必须在属性中存储数据,请创建一个计算和设置属性值的配方,并将其设置为在默认配方中执行的第一个配方。

关于chef-infra - Chef : Use library function in attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22844080/

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