You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

vagrant-berkshelf已弃用,能否仅以Chef为置备器实现Vagrant驱动构建?

Answer to Your Vagrant + Chef Provisioning Question

Hey there, let's break this down clearly since you're just using Chef as a provisioner (not developing or testing cookbooks yourself):

First, the vagrant-berkshelf Context

You're right—vagrant-berkshelf has been officially deprecated, and Test Kitchen is the recommended tool for cookbook testing and validation. But here's the key: Test Kitchen isn't required for your use case. It's built for folks who write and test cookbooks, not for someone who just wants to use pre-built cookbooks to provision Vagrant-managed VMs or DigitalOcean droplets.

Can You Still Use Chef as a Vagrant Provisioner?

Absolutely! You don't need the vagrant-berkshelf plugin to keep using Chef with Vagrant. Here are a few reliable alternatives to sync your cookbooks without relying on the deprecated plugin:

1. Use a Local Cookbooks Directory

The simplest approach is to store your cookbooks (and their dependencies) in a local directory relative to your Vagrantfile, then point Vagrant directly to it. Here's how to set this up:

  • Run berks vendor ./cookbooks (if you still use Berkshelf to manage dependencies) to download all required cookbooks into a cookbooks folder next to your Vagrantfile.
  • Configure your Vagrantfile to use this directory with Chef Solo (no Chef Server required, perfect for casual users):
    Vagrant.configure("2") do |config|
      # Your VM/Droplet config (box, provider settings, etc.)
    
      config.vm.provision "chef_solo" do |chef|
        chef.cookbook_path = "./cookbooks"
        chef.add_recipe "your-target-recipe" # Replace with your recipe name
        # Add any custom attributes here if needed
        # chef.json = { "some_attribute": "value" }
      end
    end
    

Vagrant will automatically sync this directory to your VM/droplet and use the cookbooks during provisioning.

2. Package Cookbooks into a Tarball

If you prefer to avoid syncing a full directory, you can package your cookbooks into a single tarball and have Vagrant upload that instead:

  • Run berks package locally to generate a cookbooks.tar.gz file.
  • Update your Vagrantfile to reference this tarball:
    Vagrant.configure("2") do |config|
      # Your VM/Droplet config
    
      config.vm.provision "chef_solo" do |chef|
        chef.cookbook_tarball = "./cookbooks.tar.gz"
        chef.add_recipe "your-target-recipe"
      end
    end
    

This is great for minimizing file transfer size, especially for DigitalOcean droplets where bandwidth might be a consideration.

3. Use Chef Client with a Local Repository (Optional)

If you already have a Chef Server set up, you can use Chef Client instead of Chef Solo. In this case, Vagrant will instruct the target machine to pull cookbooks directly from your Chef Server—no need to sync files locally at all. Just configure the Chef Client provisioner with your server details in the Vagrantfile.

Final Notes

All these methods work seamlessly with both local VMs and DigitalOcean droplets managed by Vagrant. You don't need to switch to Test Kitchen unless you decide to start developing or testing cookbooks down the line.

Stick with Chef Solo if you want to keep things simple (no server required) and use either the local directory or tarball approach to get your cookbooks onto your target machines reliably.

内容的提问来源于stack exchange,提问作者JL Peyret

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:39:21