Fabricio Lemos
Fabricio Lemos

Reputation: 2955

Vagrant: install git using Chef

I'm using a Chef cookbook to install Git in my Vagrant VM. Accordingly to the default configuration, the cookbook should install Git 2.8.1, but instead I'm getting Git 1.9.1.

What would be the proper way of using Chef to install a more recent Git version? To keep the configuration simple, I would still like to use Cookbooks.

This is my configuration so far:

Vagrantfile:

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/trusty64"

  config.berkshelf.enabled = true

  config.vm.provision "chef_solo" do |chef|
      chef.add_recipe "git"
  end   
end

metadata.rb:

name             'vagrant-example'

recipe 'git', 'Installs git'

Berksfile:

source "https://supermarket.chef.io"

metadata

cookbook "git"

Berksfile.lock:

DEPENDENCIES
  git
  vagrant-example
    path: .
    metadata: true

GRAPH
  build-essential (6.0.3)
    compat_resource (>= 12.10)
    mingw (>= 1.1)
    seven_zip (>= 0.0.0)
  chef_handler (1.4.0)
  compat_resource (12.10.7)
  dmg (2.4.0)
  git (4.6.0)
    build-essential (>= 0.0.0)
    dmg (>= 0.0.0)
    windows (>= 0.0.0)
    yum-epel (>= 0.0.0)
  mingw (1.2.4)
    compat_resource (>= 0.0.0)
    seven_zip (>= 0.0.0)
  seven_zip (2.0.1)
    windows (>= 1.2.2)
  vagrant-example (0.0.0)
  windows (1.44.1)
    chef_handler (>= 0.0.0)
  yum (3.11.0)
  yum-epel (0.7.0)
    yum (>= 3.6.3)

Output from Vagrant up:

==> default: Installing Cookbook Gems:
==> default: Compiling Cookbooks...
==> default: Converging 1 resources
==> default: Recipe: git::package
==> default:   
==> default: * git_client[default] action install
==> default:     
==> default: * apt_package[default :create git] action install
==> default: [2016-08-14T01:11:04+00:00] INFO: apt_package[default :create git] installed git at 1:1.9.1-1ubuntu0.3
==> default:       - install version 1:1.9.1-1ubuntu0.3 of package git
==> default: 
==> default:   
==> default: 
==> default: 
==> default: [2016-08-14T01:11:04+00:00] INFO: Chef Run complete in 13.492574359 seconds

I even tried specifying the version using Chef attributes in the Vagrantfile, but it also did not work:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"

  config.berkshelf.enabled = true

  config.vm.provision "chef_solo" do |chef|
      chef.add_recipe "git"

      chef.json = {
            "git" => {
              "version" => "2.8.1"
            }
       }
  end
end

Upvotes: 1

Views: 965

Answers (1)

coderanger
coderanger

Reputation: 54181

The git::default recipe installs from your distro packages which for Ubuntu Trusty is 1.9.1. You can use the git::source recipe to force it to compile from source which can install any version.

Upvotes: 2

Related Questions