8

I'm using Vagrant with Chef to build a Ubuntu 12.04 virtual machine. I'm using the opscode cookbooks from here: https://github.com/opscode/cookbooks

I want to use the opscode apt cookbook to install packages. I want to make sure it installs a specific version of a package, to make sure the build environment is consistent. Here's an example of what I'm trying to do:

package "git" do
  action :install
end

I know that if you install the package using apt from the command line, you can specify the version like so:

apt-get install git=1:1.7.9.5-1

But I can't figure out how to do this via the cookbook. Is this possible?

wch
  • 4,069
  • 2
  • 28
  • 36

1 Answers1

13

I think I figured it out. It's pretty simple:

package "git" do
  version "1:1.7.9.5-1"
  action :install
end
wch
  • 4,069
  • 2
  • 28
  • 36
  • 4
    It may be a good idea to put the version number into an attribute. That way you can do an upgrade (or a downgrade!) without having to upload a new cookbook. – Tim Potter May 10 '12 at 02:50
  • 1
    Could you explain a bit more in depth? I'm totally new at using this system. Thanks! – wch May 10 '12 at 06:19
  • 1
    You may want to take a look at the Chef [package resource](http://wiki.opscode.com/display/chef/Resources#Resources-Package) documentation – Dror Bereznitsky May 10 '12 at 07:11
  • 2
    Something like putting `default[:git_version] = 1.7.9.5-1` to nominate a version number in an attribute file, then use `version node[:git_version]` in your recipe. – Tim Potter May 13 '12 at 20:07