gpt4 book ai didi

chef-infra - 在配方中使用库中的类方法

转载 作者:行者123 更新时间:2023-12-05 00:26:37 27 4
gpt4 key购买 nike

我只是想在厨师中创建一本简单的食谱。我正在使用图书馆作为学习过程。

module ABC
class YumD
def self.pack (*count)
for i in 0...count.length
yum_packag "#{count[i]}" do
action :nothing
end.run_action :install
end
end
end
end

当我在配方中调用它时,我收到一个编译错误,上面写着
undefined method `yum_package' for ABC::YumD:Class

最佳答案

您无权访问库中的 Chef Recipe DSL。 DSL 方法实际上只是成熟的 Ruby 类的捷径。例如:

template '/etc/foo.txt' do
source 'foo.erb'
end

实际上“编译”(读作:“被解释”)为:

template = Chef::Resource::Template.new('/etc/foo.txt')
template.source('foo.erb')
template.run_action(:create)

所以,在你的情况下,你想使用 YumPackage :

module ABC
class YumD
def self.pack(*count)
for i in 0...count.length
package = Chef::Resource::YumPackage.new("#{count[i]}")
package.run_action(:install)
end
end
end
end

关于chef-infra - 在配方中使用库中的类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21908433/

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