[chef] Re: Installing large numbers of packages


Chronological Thread 
  • From: "Mark J. Reed" < >
  • To: " " < >
  • Subject: [chef] Re: Installing large numbers of packages
  • Date: Wed, 14 Sep 2011 07:29:37 -0400

The "iterate over a list of packages" approach seems to be pretty standard, regardless of whether the list itself be hard-coded, from an attribute, or from a data bag. 

If you don't like having the explicit loop inside your recipes, you could wrap it in an LWRP, maybe something like this:

package_list "my-package-list" do
  packages %w{foo bar baz}
  action :install
end

The provider could look something like this:

[:install, :upgrade, :remove, :purge].each do |act|
  action act do
   new_resource.packages.each do |pkg| 
      package pkg do
        action act
      end
   end
end

Of course, you'd need more code if you wanted it to be more generally useful, to handle attributes, notifies, etc. 

It seems overkillish to me, though.  I find lines like "%w<foo bar baz>.each { |p| package p }" to be pretty short, sweet and clear. 


On Wednesday, August 31, 2011, Matt Palmer < " target="_blank"> > wrote:
> I'm getting my first chef recipe in order, a simple one to prep a
> workstation -- which is mostly "install this giant list of packages".
>
> I was surprised to find that the simple, obvious way to do this:
>
>    package %w{foo bar baz} do
>        action :install
>    end
>
> Didn't work.  Resources don't accept an array as the namevar to do the
> obvious thing.  Instead, I've got to do either:
>
>    package "foo" do
>        action :install
>    end
>
>    package "bar" do
>        action :install
>    end
>
>    package "baz" do
>        action :install
>    end
>
> Which is ridiculously verbose, or else:
>
>    %w{foo bar baz}.each do |pkg|
>        package pkg do
>            action :install
>        end
>    end
>
> Which doesn't do anything for my "but you don't need to learn *much*
> Ruby" claims to the rest of the team, and still isn't as compact and
> clean as it could be.
>
> Am I missing something obvious, or is one of the above options really
> the recommended way to create big lists of resources?
>
> Thanks,
> - Matt
>



Archive powered by MHonArc 2.6.16.

§