» Chef Client Provisioner

Provisioner name: chef_client

The Vagrant Chef Client provisioner allows you to provision the guest usingChef, specifically by connectingto an existing Chef Server and registering the Vagrant machine as anode within your infrastructure.

If you are just learning Chef for the first time, you probably wantto start with the Chef Soloprovisioner.

Warning: If you are not familiar with Chef and Vagrant already,it is recommended to start with the shellprovisioner.

» Authenticating

The minimum required to use provision using Chef Client is to providea URL to the Chef Server as well as the path to the validation key sothat the node can register with the Chef Server:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "chef_client" do |chef|
  3. chef.chef_server_url = "http://mychefserver.com"
  4. chef.validation_key_path = "validation.pem"
  5. end
  6. end

The node will register with the Chef Server specified, download theproper run list for that node, and provision.

» Specifying a Run List

Normally, the Chef Server is responsible for specifying the run listfor the node. However, you can override what the Chef Server sendsdown by manually specifying a run list:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "chef_client" do |chef|
  3. # Add a recipe
  4. chef.add_recipe "apache"
  5. # Or maybe a role
  6. chef.add_role "web"
  7. end
  8. end

Remember, this will override the run list specified on the Chefserver itself.

» Environments

You can specify the environmentfor the node to come up in using the environment configuration option:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "chef_client" do |chef|
  3. # ...
  4. chef.environment = "development"
  5. end
  6. end

» Other Configuration Options

There are a few more configuration options available. These generally do notneed to be modified but are available if your Chef Server requires customizationof these variables.

» Cleanup

When you provision your Vagrant virtual machine with Chef Server, it creates anew Chef "node" entry and Chef "client" entry on the Chef Server, using thehostname of the machine. After you tear down your guest machine, Vagrant can beconfigured to do it automatically with the following settings:

  1. chef.delete_node = true
  2. chef.delete_client = true

If you do not specify it or set it to false, you must explicitly delete theseentries from the Chef Server before you provision a new one with Chef Server.For example, using Chef's built-in knife tool:

  1. $ knife node delete precise64
  2. $ knife client delete precise64

If you fail to do so, you will get the following error when Vagranttries to provision the machine with Chef Client:

  1. HTTP Request Returned 409 Conflict: Client already exists.