How to stop resource cloning in a loop for a chef recipe?
Asked Answered
M

3

5

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?

Mitchelmitchell answered 22/5, 2014 at 12:39 Comment(0)
M
4

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
Mitchelmitchell answered 22/5, 2014 at 12:54 Comment(2)
Yes, that works, but you make things more complicated than you have to.Medieval
This is exactly the same as my answer.Quechuan
Q
12

package_name is the name attribute. Just do this:

ops_pkgs.each do |pkg|
  yum_package pkg
end

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

Quechuan answered 22/5, 2014 at 15:40 Comment(0)
M
4

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
Mitchelmitchell answered 22/5, 2014 at 12:54 Comment(2)
Yes, that works, but you make things more complicated than you have to.Medieval
This is exactly the same as my answer.Quechuan
K
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/

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

Karmakarmadharaya answered 7/5, 2015 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.