2013-09-03 18:08:28 +00:00
|
|
|
|
---
|
2013-09-06 16:50:43 +00:00
|
|
|
|
page_title: "Chef Solo - Provisioning"
|
2013-09-03 18:08:28 +00:00
|
|
|
|
sidebar_current: "provisioning-chefsolo"
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Chef Solo Provisioner
|
|
|
|
|
|
|
|
|
|
**Provisioner name: `chef_solo`**
|
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
|
The Chef Solo provisioner allows you to provision the guest using
|
2015-02-24 13:31:24 +00:00
|
|
|
|
[Chef](https://www.chef.io/chef/), specifically with
|
2013-09-03 18:08:28 +00:00
|
|
|
|
[Chef Solo](http://docs.opscode.com/chef_solo.html).
|
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
|
Chef Solo is ideal for people who are already experienced with Chef,
|
2013-09-03 18:08:28 +00:00
|
|
|
|
already have Chef cookbooks, or are looking to learn Chef. Specifically,
|
|
|
|
|
this documentation page will not go into how to use Chef or how to write
|
|
|
|
|
Chef cookbooks, since Chef is a complete system that is beyond the scope
|
|
|
|
|
of a single page of documentation.
|
|
|
|
|
|
|
|
|
|
<div class="alert alert-warn">
|
|
|
|
|
<p>
|
|
|
|
|
<strong>Warning:</strong> If you're not familiar with Chef and Vagrant already,
|
|
|
|
|
I recommend starting with the <a href="/v2/provisioning/shell.html">shell
|
|
|
|
|
provisioner</a>. However, if you're comfortable with Vagrant already, Vagrant
|
|
|
|
|
is the best way to learn Chef.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2013-11-26 19:44:16 +00:00
|
|
|
|
## Options
|
|
|
|
|
|
2014-06-29 23:56:02 +00:00
|
|
|
|
This section lists the complete set of available options for the Chef Solo
|
2013-11-26 19:44:16 +00:00
|
|
|
|
provisioner. More detailed examples of how to use the provisioner are
|
|
|
|
|
available below this section.
|
|
|
|
|
|
|
|
|
|
* `cookbooks_path` (string or array) - A list of paths to where cookbooks
|
|
|
|
|
are stored. By default this is "cookbooks", expecting a cookbooks folder
|
|
|
|
|
relative to the Vagrantfile location.
|
|
|
|
|
|
2014-02-22 03:59:14 +00:00
|
|
|
|
* `data_bags_path` (string) - A path where data bags are stored. By default, no
|
|
|
|
|
data bag path is set.
|
2013-11-26 19:44:16 +00:00
|
|
|
|
|
2014-02-22 03:59:14 +00:00
|
|
|
|
* `environments_path` (string) - A path where environment definitions are
|
|
|
|
|
located. By default, no environments folder is set.
|
2013-11-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
|
* `environment` (string) - The environment you want the Chef run to be
|
2014-02-22 03:59:14 +00:00
|
|
|
|
a part of. This requires Chef 11.6.0 or later, and that `environments_path`
|
|
|
|
|
is set.
|
2013-11-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
|
* `recipe_url` (string) - URL to an archive of cookbooks that Chef will download
|
|
|
|
|
and use.
|
|
|
|
|
|
|
|
|
|
* `roles_path` (string or array) - A list of paths where roles are defined.
|
2014-02-22 03:59:14 +00:00
|
|
|
|
By default this is empty. Multiple role directories are only supported by
|
|
|
|
|
Chef 11.8.0 and later.
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
2014-01-02 22:42:40 +00:00
|
|
|
|
* `synced_folder_type` (string) - The type of synced folders to use when
|
|
|
|
|
sharing the data required for the provisioner to work properly. By default
|
|
|
|
|
this will use the default synced folder type. For example, you can set this
|
|
|
|
|
to "nfs" to use NFS synced folders.
|
|
|
|
|
|
2014-12-17 02:08:16 +00:00
|
|
|
|
In addition to all the options listed above, the Chef Solo provisioner supports
|
|
|
|
|
the [common options for all Chef provisioners](/v2/provisioning/chef_common.html).
|
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
|
## Specifying a Run List
|
|
|
|
|
|
|
|
|
|
The easiest way to get started with the Chef Solo provisioner is to just
|
2015-02-24 13:31:24 +00:00
|
|
|
|
specify a [run list](https://docs.chef.io/nodes.html#about-run-lists). This looks like:
|
2013-09-03 18:08:28 +00:00
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.add_recipe "apache"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This causes Vagrant to run Chef Solo with the "apache" cookbook. The cookbooks
|
|
|
|
|
by default are looked for in the "cookbooks" directory relative to your
|
|
|
|
|
project root. The directory structure ends up looking like this:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ tree
|
|
|
|
|
.
|
|
|
|
|
|-- Vagrantfile
|
|
|
|
|
|-- cookbooks
|
|
|
|
|
| |-- apache
|
|
|
|
|
| |-- recipes
|
|
|
|
|
| |-- default.rb
|
|
|
|
|
```
|
|
|
|
|
|
2014-09-16 18:24:35 +00:00
|
|
|
|
The order of the calls to `add_recipe` will specify the order of the run list.
|
|
|
|
|
Earlier recipes added with `add_recipe` are run before later recipes added.
|
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
|
## Custom Cookbooks Path
|
|
|
|
|
|
|
|
|
|
Instead of using the default "cookbooks" directory, a custom cookbooks
|
|
|
|
|
path can also be set via the `cookbooks_path` configuration directive:
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.cookbooks_path = "my_cookbooks"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The path can be relative or absolute. If it is relative, it is relative
|
|
|
|
|
to the project root.
|
|
|
|
|
|
|
|
|
|
The configuration value can also be an array of paths:
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.cookbooks_path = ["cookbooks", "my_cookbooks"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Roles
|
|
|
|
|
|
2015-02-24 13:31:24 +00:00
|
|
|
|
Vagrant also supports provisioning with [Chef roles](http://docs.chef.io/roles.html).
|
2013-09-03 18:08:28 +00:00
|
|
|
|
This is done by specifying a path to a roles folder where roles are defined
|
|
|
|
|
and by adding roles to your run list:
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.roles_path = "roles"
|
|
|
|
|
chef.add_role("web")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Just like the cookbooks path, the roles path is relative to the project
|
|
|
|
|
root if a relative path is given.
|
|
|
|
|
|
2014-02-22 03:59:14 +00:00
|
|
|
|
The configuration value can also be an array of paths on Chef 11.8.0 and newer.
|
|
|
|
|
On older Chef versions only the first path is used.
|
|
|
|
|
|
2013-09-06 16:50:43 +00:00
|
|
|
|
**Note:** The name of the role file must be the same as the role name.
|
2013-09-04 01:48:36 +00:00
|
|
|
|
For example the `web` role must be in the `roles_path` as web.json or web.rb.
|
2013-09-04 04:06:45 +00:00
|
|
|
|
This is required by Chef itself, and isn't a limitation imposed by
|
|
|
|
|
Vagrant.
|
2013-09-04 01:48:36 +00:00
|
|
|
|
|
2013-09-03 18:08:28 +00:00
|
|
|
|
## Data Bags
|
|
|
|
|
|
2015-02-24 13:31:24 +00:00
|
|
|
|
[Data bags](http://docs.chef.io/data_bags.html) are also
|
2013-09-03 18:08:28 +00:00
|
|
|
|
supported by the Chef Solo provisioner. This is done by specifying
|
|
|
|
|
a path to your data bags directory:
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.data_bags_path = "data_bags"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Custom JSON Data
|
|
|
|
|
|
|
|
|
|
Additional configuration data for Chef attributes can be passed in
|
2014-06-29 23:56:02 +00:00
|
|
|
|
to Chef Solo. This is done by setting the `json` property with a Ruby
|
2013-09-03 18:08:28 +00:00
|
|
|
|
hash (dictionary-like object), which is converted to JSON and passed
|
|
|
|
|
in to Chef:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
# ...
|
|
|
|
|
|
|
|
|
|
chef.json = {
|
|
|
|
|
"apache" => {
|
|
|
|
|
"listen_address" => "0.0.0.0"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Hashes, arrays, etc. can be used with the JSON configuration object. Basically,
|
|
|
|
|
anything that can be turned cleanly into JSON works.
|
|
|
|
|
|
|
|
|
|
## Custom Node Name
|
|
|
|
|
|
|
|
|
|
You can specify a custom node name by setting the `node_name` property. This
|
|
|
|
|
is useful for cookbooks that may depend on this being set to some sort
|
|
|
|
|
of value. Example:
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
config.vm.provision "chef_solo" do |chef|
|
|
|
|
|
chef.node_name = "foo"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
```
|