如何在循环中停止资源克隆以获取厨师食谱?

时间:2021-10-05 00:23:25

I have a chef recipe that installs packages in a loop:

我有一个厨师食谱,可以在一个循环中安装包:

pkgs.each do |pkg|
  yum_package "tools" do
    package_name pkg
    action :install
  end
end

This recipe is however throwing the following error:

但是这个方法会引发以下错误:

[2014-05-22T08:26:13-04:00] WARN: Cloning resource attributes for yum_package[tools] from prior resource (CHEF-3694)
[2014-05-22T08:26:13-04:00] WARN: Previous yum_package[tools]: /var/chef/cache/cookbooks/tools/recipes/default.rb:9:in `block in from_file'

Eventually, this feature is going to be removed. So, I need to find a way to properly loop in a chef recipe without throwing this warning; I've had no luck thus far trying to figure this out; I'm wondering if anyone else has a solution?

最终,此功能将被删除。所以,我需要找到一种方法来正确地循环一个厨师食谱而不抛出这个警告;到目前为止,我没有运气试图解决这个问题;我想知道是否有其他人有解决方案?

3 个解决方案

#1


9  

package_name is the name attribute. Just do this:

package_name是name属性。这样做:

ops_pkgs.each do |pkg|
  yum_package pkg
end

You do not even need to block because action :install is the default action.

您甚至不需要阻止因为action:install是默认操作。

#2


3  

I made the resource in the loop unique to fix the issue:

我在循环中使资源独一无二,以解决问题:

ops_pkgs.each do |pkg|
  yum_package "tools #{pkg}" do
    package_name pkg
    action :install
  end
end

#3


0  

Old question I know, but I wanted to at least get some experts' opinions on this. Maybe it is a better solution to use the cookbook which acknowledges that you probably do want it to clone and merge and not throw a warning about it:

老问题我知道,但我想至少得到一些专家的意见。也许这是一个更好的解决方案,使用食谱,承认你可能希望它克隆和合并,而不是发出警告:

http://scottwb.com/blog/2014/01/24/defeating-the-infamous-chef-3694-warning/

http://scottwb.com/blog/2014/01/24/defeating-the-infamous-chef-3694-warning/

This only works for the action, but it could be extended to others.

这仅适用于该操作,但可以扩展到其他操作。

#1


9  

package_name is the name attribute. Just do this:

package_name是name属性。这样做:

ops_pkgs.each do |pkg|
  yum_package pkg
end

You do not even need to block because action :install is the default action.

您甚至不需要阻止因为action:install是默认操作。

#2


3  

I made the resource in the loop unique to fix the issue:

我在循环中使资源独一无二,以解决问题:

ops_pkgs.each do |pkg|
  yum_package "tools #{pkg}" do
    package_name pkg
    action :install
  end
end

#3


0  

Old question I know, but I wanted to at least get some experts' opinions on this. Maybe it is a better solution to use the cookbook which acknowledges that you probably do want it to clone and merge and not throw a warning about it:

老问题我知道,但我想至少得到一些专家的意见。也许这是一个更好的解决方案,使用食谱,承认你可能希望它克隆和合并,而不是发出警告:

http://scottwb.com/blog/2014/01/24/defeating-the-infamous-chef-3694-warning/

http://scottwb.com/blog/2014/01/24/defeating-the-infamous-chef-3694-warning/

This only works for the action, but it could be extended to others.

这仅适用于该操作,但可以扩展到其他操作。