2013-08-27 17:29:52 -04:00
|
|
|
---
|
2015-07-22 22:31:00 -04:00
|
|
|
layout: docs
|
2017-03-25 18:13:52 -04:00
|
|
|
sidebar_current: docs-provisioners-chef-solo
|
|
|
|
page_title: Chef Solo - Provisioners
|
|
|
|
description: |-
|
|
|
|
The chef-solo Packer provisioner installs and configures software on machines
|
|
|
|
built by Packer using chef-solo. Cookbooks can be uploaded from your local
|
|
|
|
machine to the remote machine or remote paths can be used.
|
|
|
|
---
|
2013-08-27 17:29:52 -04:00
|
|
|
|
|
|
|
# Chef Solo Provisioner
|
|
|
|
|
|
|
|
Type: `chef-solo`
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The Chef solo Packer provisioner installs and configures software on machines
|
|
|
|
built by Packer using [chef-solo](https://docs.chef.io/chef_solo.html).
|
|
|
|
Cookbooks can be uploaded from your local machine to the remote machine or
|
|
|
|
remote paths can be used.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
|
|
|
The provisioner will even install Chef onto your machine if it isn't already
|
2015-06-07 09:12:05 -04:00
|
|
|
installed, using the official Chef installers provided by Chef Inc.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The example below is fully functional and expects cookbooks in the "cookbooks"
|
|
|
|
directory relative to your working directory.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```json
|
2013-08-27 17:29:52 -04:00
|
|
|
{
|
|
|
|
"type": "chef-solo",
|
|
|
|
"cookbook_paths": ["cookbooks"]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-08-27 17:29:52 -04:00
|
|
|
|
|
|
|
## Configuration Reference
|
|
|
|
|
|
|
|
The reference of available configuration options is listed below. No
|
|
|
|
configuration is actually required, but at least `run_list` is recommended.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `chef_environment` (string) - The name of the `chef_environment` sent to the
|
2015-07-22 23:25:58 -04:00
|
|
|
Chef server. By default this is empty and will not use an environment
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `config_template` (string) - Path to a template that will be used for the
|
2015-07-22 23:25:58 -04:00
|
|
|
Chef configuration file. By default Packer only sets configuration it needs
|
|
|
|
to match the settings set in the provisioner configuration. If you need to
|
|
|
|
set configurations that the Packer provisioner doesn't support, then you
|
|
|
|
should use a custom configuration template. See the dedicated "Chef
|
|
|
|
Configuration" section below for more details.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `cookbook_paths` (array of strings) - This is an array of paths to
|
2015-07-22 23:25:58 -04:00
|
|
|
"cookbooks" directories on your local filesystem. These will be uploaded to
|
|
|
|
the remote machine in the directory specified by the `staging_directory`. By
|
|
|
|
default, this is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `data_bags_path` (string) - The path to the "data\_bags" directory on your
|
2015-07-22 23:25:58 -04:00
|
|
|
local filesystem. These will be uploaded to the remote machine in the
|
|
|
|
directory specified by the `staging_directory`. By default, this is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `encrypted_data_bag_secret_path` (string) - The path to the file containing
|
2015-07-22 23:25:58 -04:00
|
|
|
the secret for encrypted data bags. By default, this is empty, so no secret
|
|
|
|
will be available.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `environments_path` (string) - The path to the "environments" directory on
|
2015-07-22 23:25:58 -04:00
|
|
|
your local filesystem. These will be uploaded to the remote machine in the
|
|
|
|
directory specified by the `staging_directory`. By default, this is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `execute_command` (string) - The command used to execute Chef. This has
|
2015-07-22 23:25:58 -04:00
|
|
|
various [configuration template
|
2017-03-28 18:28:34 -04:00
|
|
|
variables](/docs/templates/engine.html) available. See
|
2015-07-22 23:25:58 -04:00
|
|
|
below for more information.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `guest_os_type` (string) - The target guest OS type, either "unix" or
|
2015-08-20 16:56:58 -04:00
|
|
|
"windows". Setting this to "windows" will cause the provisioner to use
|
|
|
|
Windows friendly paths and commands. By default, this is "unix".
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `install_command` (string) - The command used to install Chef. This has
|
2015-07-22 23:25:58 -04:00
|
|
|
various [configuration template
|
2017-03-28 18:28:34 -04:00
|
|
|
variables](/docs/templates/engine.html) available. See
|
2015-07-22 23:25:58 -04:00
|
|
|
below for more information.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `json` (object) - An arbitrary mapping of JSON that will be available as
|
2015-07-22 23:25:58 -04:00
|
|
|
node attributes while running Chef.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `prevent_sudo` (boolean) - By default, the configured commands that are
|
2015-07-22 23:25:58 -04:00
|
|
|
executed to install and run Chef are executed with `sudo`. If this is true,
|
2015-08-20 16:56:58 -04:00
|
|
|
then the sudo will be omitted. This has no effect when guest_os_type is
|
|
|
|
windows.
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `remote_cookbook_paths` (array of strings) - A list of paths on the remote
|
2015-07-22 23:25:58 -04:00
|
|
|
machine where cookbooks will already exist. These may exist from a previous
|
|
|
|
provisioner or step. If specified, Chef will be configured to look for
|
|
|
|
cookbooks here. By default, this is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `roles_path` (string) - The path to the "roles" directory on your
|
2015-07-22 23:25:58 -04:00
|
|
|
local filesystem. These will be uploaded to the remote machine in the
|
|
|
|
directory specified by the `staging_directory`. By default, this is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `run_list` (array of strings) - The [run
|
2015-07-22 23:25:58 -04:00
|
|
|
list](https://docs.chef.io/run_lists.html) for Chef. By default this
|
|
|
|
is empty.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `skip_install` (boolean) - If true, Chef will not automatically be installed
|
2015-07-22 23:25:58 -04:00
|
|
|
on the machine using the Chef omnibus installers.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `staging_directory` (string) - This is the directory where all the
|
2015-08-20 16:56:58 -04:00
|
|
|
configuration of Chef by Packer will be placed. By default this is
|
|
|
|
"/tmp/packer-chef-solo" when guest_os_type unix and
|
|
|
|
"$env:TEMP/packer-chef-solo" when windows. This directory doesn't need to
|
|
|
|
exist but must have proper permissions so that the user that Packer uses is
|
|
|
|
able to create directories and write into this folder. If the permissions
|
|
|
|
are not correct, use a shell provisioner prior to this to configure it
|
|
|
|
properly.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
2013-09-16 02:28:41 -04:00
|
|
|
## Chef Configuration
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
By default, Packer uses a simple Chef configuration file in order to set the
|
|
|
|
options specified for the provisioner. But Chef is a complex tool that supports
|
|
|
|
many configuration options. Packer allows you to specify a custom configuration
|
|
|
|
template if you'd like to set custom configurations.
|
2013-09-16 02:28:41 -04:00
|
|
|
|
|
|
|
The default value for the configuration template is:
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```liquid
|
2013-09-16 02:28:41 -04:00
|
|
|
cookbook_path [{{.CookbookPaths}}]
|
|
|
|
```
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
This template is a [configuration
|
2017-03-28 18:28:34 -04:00
|
|
|
template](/docs/templates/engine.html) and has a set of
|
2015-07-22 22:31:00 -04:00
|
|
|
variables available to use:
|
2013-09-16 02:28:41 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `ChefEnvironment` - The current enabled environment. Only non-empty if the
|
2015-07-22 23:25:58 -04:00
|
|
|
environment path is set.
|
2017-03-25 18:13:52 -04:00
|
|
|
- `CookbookPaths` is the set of cookbook paths ready to embedded directly into
|
2015-07-22 23:25:58 -04:00
|
|
|
a Ruby array to configure Chef.
|
2017-03-25 18:13:52 -04:00
|
|
|
- `DataBagsPath` is the path to the data bags folder.
|
|
|
|
- `EncryptedDataBagSecretPath` - The path to the encrypted data bag secret
|
|
|
|
- `EnvironmentsPath` - The path to the environments folder.
|
|
|
|
- `RolesPath` - The path to the roles folder.
|
2013-09-16 02:28:41 -04:00
|
|
|
|
2013-08-27 17:29:52 -04:00
|
|
|
## Execute Command
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
By default, Packer uses the following command (broken across multiple lines for
|
|
|
|
readability) to execute Chef:
|
2013-08-27 17:29:52 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```liquid
|
2013-10-24 21:33:06 -04:00
|
|
|
{{if .Sudo}}sudo {{end}}chef-solo \
|
2013-08-27 17:29:52 -04:00
|
|
|
--no-color \
|
|
|
|
-c {{.ConfigPath}} \
|
|
|
|
-j {{.JsonPath}}
|
|
|
|
```
|
|
|
|
|
2015-08-20 16:56:58 -04:00
|
|
|
When guest_os_type is set to "windows", Packer uses the following command to
|
|
|
|
execute Chef. The full path to Chef is required because the PATH environment
|
|
|
|
variable changes don't immediately propogate to running processes.
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```liquid
|
2015-08-20 16:56:58 -04:00
|
|
|
c:/opscode/chef/bin/chef-solo.bat \
|
|
|
|
--no-color \
|
|
|
|
-c {{.ConfigPath}} \
|
|
|
|
-j {{.JsonPath}}
|
|
|
|
```
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
This command can be customized using the `execute_command` configuration. As you
|
|
|
|
can see from the default value above, the value of this configuration can
|
|
|
|
contain various template variables, defined below:
|
2013-08-27 17:29:52 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
- `ConfigPath` - The path to the Chef configuration file.
|
|
|
|
- `JsonPath` - The path to the JSON attributes file for the node.
|
|
|
|
- `Sudo` - A boolean of whether to `sudo` the command or not, depending on the
|
2015-07-22 23:25:58 -04:00
|
|
|
value of the `prevent_sudo` configuration.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
|
|
|
## Install Command
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
By default, Packer uses the following command (broken across multiple lines for
|
|
|
|
readability) to install Chef. This command can be customized if you want to
|
|
|
|
install Chef in another way.
|
2013-08-27 17:29:52 -04:00
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```text
|
2015-06-07 09:12:05 -04:00
|
|
|
curl -L https://www.chef.io/chef/install.sh | \
|
2013-08-27 17:29:52 -04:00
|
|
|
{{if .Sudo}}sudo{{end}} bash
|
|
|
|
```
|
|
|
|
|
2015-08-20 16:56:58 -04:00
|
|
|
When guest_os_type is set to "windows", Packer uses the following command to
|
|
|
|
install the latest version of Chef:
|
|
|
|
|
2017-03-25 18:13:52 -04:00
|
|
|
```text
|
2015-08-20 16:56:58 -04:00
|
|
|
powershell.exe -Command "(New-Object System.Net.WebClient).DownloadFile('http://chef.io/chef/install.msi', 'C:\\Windows\\Temp\\chef.msi');Start-Process 'msiexec' -ArgumentList '/qb /i C:\\Windows\\Temp\\chef.msi' -NoNewWindow -Wait"
|
|
|
|
```
|
|
|
|
|
2013-08-27 17:29:52 -04:00
|
|
|
This command can be customized using the `install_command` configuration.
|