How to control the version of Chef that Vagrant uses to provision VMs?

后端 未结 6 1115
眼角桃花
眼角桃花 2020-12-07 08:26

A current Chef recipe isn\'t running because of a bug in version 0.10.10. How can I upgrade the version of Chef that Vagrant uses, to 0.10.12?

I don\'t want to just

相关标签:
6条回答
  • 2020-12-07 09:05

    There are a number of options you can specify when using Chef for provisioning. One of these is version, which allows you to specify the Chef version you want.

    For example, see the chef.version line in this extract from a Vagrantfile of mine:

    config.vm.provision :chef_solo do |chef|
       chef.version = "10.14.2"
       chef.cookbooks_path = "cookbooks"
       chef.add_recipe("vagrant_main")
     end
    
    0 讨论(0)
  • 2020-12-07 09:10

    I am unable to post comments on answers, but I wanted to add a note to Bryan Larsen's answer above. In order to get his provisioning command to work, I needed to add a line before it to be able to build the gem native extensions during install of the new Chef version. Therefore, it became:

    config.vm.provision :shell, inline: 'apt-get install ruby1.9.1-dev'
    config.vm.provision :shell, inline: 'gem install chef --version 11.4.4 --no-rdoc --no-ri'
    

    This was on Ubuntu 13.04, in case that matters to anyone.

    0 讨论(0)
  • 2020-12-07 09:14

    Using the Vagrant plugin vagrant-omnibus worked great for me:

    vagrant plugin install vagrant-omnibus
    

    You can then simply configure your chef version in the Vagrantfile before doing the provisioning:

    config.omnibus.chef_version = :latest
    

    You can also specify a specific version:

    config.omnibus.chef_version = '11.6.0'
    
    0 讨论(0)
  • 2020-12-07 09:18

    Rebuild the base box. First, bring it up without provisioning and SSH to it.

    vagrant up --no-provision 
    vagrant ssh
    

    Then, perform the commands you need to update the box. This can include updating Chef and Ruby. Optionally, update the packages for the OS, etc. You should clean up the box of everything that isn't required, such as downloaded package files or caches.

    For example, I use the Opscode Omnibus Full Stack Installer for Chef in my Vagrant boxes (originally built with VeeWee), and I update the packages, too.

    sudo dpkg --purge chef chef-full
    sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash
    sudo apt-get update && sudo aptitude safe-upgrade
    sudo rm /var/cache/apt/archives/*.deb
    

    Don't forget to "zero" the disk to reduce the size.

    # a bunch of commands like gem install chef, apt-get upgrade, whatever
    sudo dd if=/dev/zero of=/EMPTY bs=1M
    sudo rm /EMPTY
    exit
    

    Then, package the box up and add it to your Vagrant environment for use.

    vagrant package
    vagrant box add mynewlucid32 package.box
    

    If you want to use the same box name, you'll need to remove the existing box (~/.vagrant.d/boxes/BOXNAME) first.

    0 讨论(0)
  • 2020-12-07 09:19

    If you are using Chef Test Kitchen, then you can specify the Chef version in .kitchen.yml file, like this:

    provisioner:
      name: chef_zero
      require_chef_omnibus: 12.6.0
    
    0 讨论(0)
  • 2020-12-07 09:22

    Add the lines

    config.vm.provision :shell, :inline => 'apt-get install build-essential ruby1.9.1-dev --no-upgrade --yes'
    config.vm.provision :shell, :inline => "gem install chef --version 11.4.2 --no-rdoc --no-ri --conservative"
    

    to your Vagrantfile before your config.vm.provision :chef_solo block.

    props to hauraki's comment on http://dougireton.com/blog/2012/12/23/automatically-upgrading-chef-client-on-vagrant-up/

    edited to include Jason Mayfield's comment. Make sure and give him an upvote too. I added --no-upgrade to speed things up and match the --conservative on the second line. You could instead do what Jason did, and remove both the --no-upgrade and --conservative.

    edited to include suggested edit by anonymous user228653

    0 讨论(0)
提交回复
热议问题