gpt4 book ai didi

chef-infra - 如何在 Chef 中定义和调用数组?

转载 作者:行者123 更新时间:2023-12-04 12:47:15 24 4
gpt4 key购买 nike

下面是我用来复制许多文件的资源。

['contacts_nagios2.cfg','generic-host_nagios2.cfg','generic-service_nagios2.cfg','hostgroups_nagios2.cfg','services_nagios2.cfg','timeperiods_nagios2.cfg'].each do |file|
cookbook_file "/etc/nagios3/conf.d/#{file}" do
source "#{file}"
mode '0644'
end
end

我们可以定义['contacts_nagios2.cfg','generic-host_nagios2.cfg','generic-service_nagios2.cfg','hostgroups_nagios2.cfg','services_nagios2.cfg','timeperiods_nagios2.cfg'] 作为同一配方中的一个属性?

最佳答案

这将创建一个数组类型的属性,并且可以在配方文件中定义:

node.default['nagios_config_files']=['contacts_nagios2.cfg','generic-host_nagios2.cfg','generic-service_nagios2.cfg','hostgroups_nagios2.cfg','services_nagios2.cfg','timeperiods_nagios2.cfg']

如果你想添加,你可以稍后做:

node.default['nagios_config_files']|=['more_configs.cfg','even_more_configs.cfg']

(注意“=”符号前的竖线“|”。)

然后你可以像以前一样使用属性:

node['nagios_config_files'].each do |file|
cookbook_file "/etc/nagios3/conf.d/#{file}" do
source "#{file}"
mode '0644'
end
end

关于chef-infra - 如何在 Chef 中定义和调用数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43718803/

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