使用Vagrant驱动程序进行厨师调配

时间:2018-09-05 15:47:18

标签: vagrant chef chef-provisioning

我想与Chef Provisioning一起踏上第一步,并尝试运行我的第一个示例。我有点迷茫,因为我认为这是一个简单的示例,但对我却没有用,很显然,我还需要遵循另一个步骤才能继续。

使用的软件版本为:

Chef Development Kit Version: 3.0.36
chef-client version: 14.1.12
delivery version: master (7206afaf4cf29a17d2144bb39c55b7212cfafcc7)
berks version: 7.0.2
kitchen version: 1.21.2
inspec version: 2.1.72

运行以下命令后:

mkdir chef-repo
cd chef-repo
chef generate app cool-app
mkdir -p cool-app/provision/recipes
nano cool-app/provision/recipes/app-cluster.rb 

将cool-app / provision / recipes / app-cluster.rb内容编辑为以下内容:

require 'chef/provisioning/vagrant_driver'
with_driver 'vagrant'

vagrant_box 'centos-7.1' do
  url 'https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.1/vagrant-centos-7.1.box'
end

with_machine_options :vagrant_options => {
  'vm.box' => 'centos-7.1'
}

machine 'db' do
  recipe 'postgresql'
  converge true
end

num_webservers = 2
machine_batch do
  1.upto(num_webservers) do |i|
    machine "web#{i}" do
      recipe 'apache'
      converge true
    end
  end
end

然后我尝试使用命令运行示例

chef provision --no-policy --cookbook ./cool-app/provision/ -r app-cluster

这时,我得到以下输出:

================================================================================
Recipe Compile Error in D:/cooking/provisioning/chef-repo/cool-app/provision/recipes/app-cluster.rb
================================================================================

LoadError
---------
cannot load such file -- chef/provisioning/vagrant_driver

Cookbook Trace:
---------------
  D:/cooking/provisioning/chef-repo/cool-app/provision/recipes/app-cluster.rb:1:in `from_file'

Relevant File Content:
----------------------
D:/cooking/provisioning/chef-repo/cool-app/provision/recipes/app-cluster.rb:

  1>> require 'chef/provisioning/vagrant_driver'
  2:  with_driver 'vagrant'
  3:
  4:  vagrant_box 'centos-7.1' do
  5:    url 'https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.1/vagrant-centos-7.1.box'
  6:  end
  7:
  8:  with_machine_options :vagrant_options => {
  9:    'vm.box' => 'centos-7.1'
 10:  }

System Info:
------------
chef_version=14.1.12
ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32]
program_name=C:/opscode/chefdk/bin/chef
executable=C:/opscode/chefdk/bin/chef

Error: cannot load such file -- chef/provisioning/vagrant_driver

我需要做些什么来将流浪汉驱动程序添加到厨师食谱中吗?我遵循的示例似乎未提及有关添加vagrant_driver文件的任何内容,因此我认为该文件将内置在其中?

1 个答案:

答案 0 :(得分:1)

意识到厨师提供的流浪者是红宝石之后,我能够检查它是否已安装。我检查了我的宝石库,但它不存在,那里只有aws和雾的变体。

我运行了命令chef gem install chef-provisioning-vagrant,该命令随后安装了预配器,并且此后效果更好。我猜这是我写的那本书编写以来,已从ChefDK中删除了该预配器。