通过Chef solo和Vagrant安装apt包

时间:2016-01-03 03:54:54

标签: ubuntu vagrant chef

我需要为Ubuntu安装libgmp3-dev包,

Vagrant档案:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["chef/site-cookbooks", "cookbooks"]
    chef.add_recipe "build-essential"
    chef.add_recipe "apt"
  end
end

厨师/位点的食谱/系统/食谱/ default.rb:

package 'libgmp3-dev' do
  action :install
end

但是当我创建虚拟机时,里面没有libgmp3-dev

更新。找到了这个解决方案:

config.vm.provision :shell, :inline => 'sudo apt-get install libgmp3-dev -y'

但我认为这不是一个很好的解决方案

2 个答案:

答案 0 :(得分:3)

如果您使用的是system cookbook from Supermarket,则需要添加system::install_packages食谱并设置node['system']['packages']['install']属性:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["chef/site-cookbooks", "cookbooks"]
    chef.add_recipe "build-essential"
    chef.add_recipe "apt"

    chef.add_recipe "system::install_packages"
    chef.json = {
      "system" => {
        "packages" => {
          "install" => ["libgmp3-dev"]
        }
      }
    }
  end
end

如果您使用自己的system食谱和粘贴的package指令,我认为the solution proposed by Patrick Lee就足够了。

答案 1 :(得分:1)

基于Vagrant docs for the Chef Solo provisioner,您似乎错过了Vagrantfile中的食谱...

chef.add_recipe "system"