» 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:
Vagrant.configure("2") do |config|
config.vm.provision "chef_client" do |chef|
chef.chef_server_url = "http://mychefserver.com"
chef.validation_key_path = "validation.pem"
end
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:
Vagrant.configure("2") do |config|
config.vm.provision "chef_client" do |chef|
# Add a recipe
chef.add_recipe "apache"
# Or maybe a role
chef.add_role "web"
end
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:
Vagrant.configure("2") do |config|
config.vm.provision "chef_client" do |chef|
# ...
chef.environment = "development"
end
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.
client_key_path
node_name
validation_client_name
In addition to all the options listed above, the Chef Client provisioner supportsthe common options for all Chef provisioners.
» 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:
chef.delete_node = true
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:
$ knife node delete precise64
$ 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:
HTTP Request Returned 409 Conflict: Client already exists.