vagrantchef-infrachef-provisioning

Chef Provisioning with Vagrant Driver


I'm tyring to get off the ground with Chef Provisioning and am trying to run my first example. I'm a bit lost as what I thought would be an easy example is not working for me, clearly there is another step that I need to follow in order to proceed further.

The versions of the software in use are:

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

After running the following commands:

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 

Edit cool-app/provision/recipes/app-cluster.rb content to the following:

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

I then attempt to run the example with the command

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

At this point, I get the following output:

================================================================================
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

Is there something I need to do to add the vagrant driver to the chef cookbook. The example I am following does not appear to mention anything about adding a vagrant_driver file, so I thought it would be built in?


Solution

  • After realising the the chef-provisoning-vagrant was a ruby gem I was able to check if it was installed. I checked my gem library and it was not present, only aws and fog variants were there.

    I ran the command chef gem install chef-provisioning-vagrant which then installed the provisioner and it worked better after that. I guess this provisioner has been removed from the ChefDK since the book I was looking at was written.