2013-09-03 18:08:28 +00:00
|
|
|
---
|
2016-01-19 18:08:53 +00:00
|
|
|
layout: "docs"
|
2013-09-06 16:50:43 +00:00
|
|
|
page_title: "Chef Client - Provisioning"
|
2013-09-03 18:08:28 +00:00
|
|
|
sidebar_current: "provisioning-chefclient"
|
2016-01-19 18:08:53 +00:00
|
|
|
description: |-
|
2016-01-19 19:54:13 +00:00
|
|
|
The Vagrant Chef Client provisioner allows you to provision the guest using
|
|
|
|
Chef, specifically by connecting to an existing Chef Server and registering
|
|
|
|
the Vagrant machine as a node within your infrastructure.
|
2013-09-03 18:08:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Chef Client Provisioner
|
|
|
|
|
|
|
|
**Provisioner name: `chef_client`**
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
The Vagrant Chef Client provisioner allows you to provision the guest using
|
|
|
|
[Chef](https://www.chef.io/chef/), specifically by connecting
|
2013-09-03 18:08:28 +00:00
|
|
|
to an existing Chef Server and registering the Vagrant machine as a
|
|
|
|
node within your infrastructure.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
If you are just learning Chef for the first time, you probably want
|
|
|
|
to start with the [Chef Solo](/docs/provisioning/chef_solo.html)
|
2013-09-03 18:08:28 +00:00
|
|
|
provisioner.
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
<div class="alert alert-warning">
|
2016-01-19 19:54:13 +00:00
|
|
|
<strong>Warning:</strong> If you are not familiar with Chef and Vagrant already,
|
2018-11-12 16:40:53 +00:00
|
|
|
it is recommended to start with the <a href="/docs/provisioning/shell.html">shell
|
2016-01-19 19:54:13 +00:00
|
|
|
provisioner</a>.
|
2013-09-03 18:08:28 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
## Authenticating
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
The minimum required to use provision using Chef Client is to provide
|
|
|
|
a URL to the Chef Server as well as the path to the validation key so
|
|
|
|
that the node can register with the Chef Server:
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
2013-09-06 16:50:43 +00:00
|
|
|
config.vm.provision "chef_client" do |chef|
|
2014-08-12 21:07:16 +00:00
|
|
|
chef.chef_server_url = "http://mychefserver.com"
|
2013-09-03 18:08:28 +00:00
|
|
|
chef.validation_key_path = "validation.pem"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
The node will register with the Chef Server specified, download the
|
2013-09-03 18:08:28 +00:00
|
|
|
proper run list for that node, and provision.
|
|
|
|
|
|
|
|
## Specifying a Run List
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
Normally, the Chef Server is responsible for specifying the run list
|
|
|
|
for the node. However, you can override what the Chef Server sends
|
2013-09-03 18:08:28 +00:00
|
|
|
down by manually specifying a run list:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
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 Chef
|
|
|
|
server itself.
|
|
|
|
|
|
|
|
## Environments
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
You can specify the [environment](https://docs.chef.io/environments.html)
|
2013-09-03 18:08:28 +00:00
|
|
|
for the node to come up in using the `environment` configuration option:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.provision "chef_client" do |chef|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
chef.environment = "development"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
## Other Configuration Options
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
There are a few more configuration options available. These generally do not
|
2014-06-29 23:56:02 +00:00
|
|
|
need to be modified but are available if your Chef Server requires customization
|
2014-12-17 02:08:16 +00:00
|
|
|
of these variables.
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
* `client_key_path`
|
|
|
|
* `node_name`
|
|
|
|
* `validation_client_name`
|
|
|
|
|
2014-12-17 02:08:16 +00:00
|
|
|
In addition to all the options listed above, the Chef Client provisioner supports
|
2016-01-19 18:08:53 +00:00
|
|
|
the [common options for all Chef provisioners](/docs/provisioning/chef_common.html).
|
2014-12-17 02:08:16 +00:00
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
## Cleanup
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
When you provision your Vagrant virtual machine with Chef Server, it creates a
|
|
|
|
new Chef "node" entry and Chef "client" entry on the Chef Server, using the
|
2013-12-10 18:47:39 +00:00
|
|
|
hostname of the machine. After you tear down your guest machine, Vagrant can be
|
|
|
|
configured to do it automatically with the following settings:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
chef.delete_node = true
|
|
|
|
chef.delete_client = true
|
|
|
|
```
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
If you do not specify it or set it to `false`, you must explicitly delete these
|
2014-06-29 23:56:02 +00:00
|
|
|
entries from the Chef Server before you provision a new one with Chef Server.
|
2013-12-10 18:47:39 +00:00
|
|
|
For example, using Chef's built-in `knife` tool:
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
$ knife node delete precise64
|
|
|
|
$ knife client delete precise64
|
|
|
|
```
|
|
|
|
|
2016-01-19 18:08:53 +00:00
|
|
|
If you fail to do so, you will get the following error when Vagrant
|
2014-06-29 23:56:02 +00:00
|
|
|
tries to provision the machine with Chef Client:
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
HTTP Request Returned 409 Conflict: Client already exists.
|
|
|
|
```
|