2

我很想开始使用 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 文件的内容,所以我认为它会被内置?

4

1 回答 1

1

在意识到 chef-provisioning-vagrant 是一个红宝石之后,我能够检查它是否已安装。我检查了我的 gem 库,它不存在,只有 aws 和fog 变体在那里。

我运行了命令chef gem install chef-provisioning-vagrant,然后安装了provisioner,之后效果更好。我想自从我正在看的书写完以来,这个配置器已经从 ChefDK 中删除了。

于 2018-09-05T16:05:50.397 回答