2014-02-24 12:45:04 -05:00
|
|
|
---
|
2020-03-18 18:46:47 -04:00
|
|
|
description: >
|
|
|
|
The chef-client Packer provisioner installs and configures software on
|
|
|
|
machines
|
|
|
|
|
|
|
|
built by Packer using chef-client. Packer configures a Chef client to talk to
|
|
|
|
a
|
|
|
|
|
|
|
|
remote Chef Server to provision the machine.
|
2015-07-22 22:31:00 -04:00
|
|
|
layout: docs
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: Chef Client - Provisioners
|
|
|
|
sidebar_current: docs-provisioners-chef-client
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2014-02-24 12:45:04 -05:00
|
|
|
|
|
|
|
# Chef Client Provisioner
|
|
|
|
|
|
|
|
Type: `chef-client`
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The Chef Client Packer provisioner installs and configures software on machines
|
2015-08-20 19:26:18 -04:00
|
|
|
built by Packer using [chef-client](https://docs.chef.io/chef_client.html).
|
2018-10-26 20:02:51 -04:00
|
|
|
Packer configures a Chef client to talk to a remote Chef Server to provision
|
|
|
|
the machine.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
|
|
|
The provisioner will even install Chef onto your machine if it isn't already
|
2015-08-20 19:26:18 -04:00
|
|
|
installed, using the official Chef installers provided by Chef.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The example below is fully functional. It will install Chef onto the remote
|
|
|
|
machine and run Chef client.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2014-02-24 12:45:04 -05:00
|
|
|
{
|
|
|
|
"type": "chef-client",
|
2014-07-16 18:49:26 -04:00
|
|
|
"server_url": "https://mychefserver.com/"
|
2014-02-24 12:45:04 -05:00
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Note: to properly clean up the Chef node and client the machine on which packer
|
|
|
|
is running must have knife on the path and configured globally, i.e,
|
2017-03-25 18:13:52 -04:00
|
|
|
`~/.chef/knife.rb` must be present and configured for the target chef server
|
2014-09-03 23:38:01 -04:00
|
|
|
|
2014-02-24 12:45:04 -05:00
|
|
|
## Configuration Reference
|
|
|
|
|
|
|
|
The reference of available configuration options is listed below. No
|
2014-09-24 14:19:28 -04:00
|
|
|
configuration is actually required.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `chef_environment` (string) - The name of the chef_environment sent to the
|
|
|
|
Chef server. By default this is empty and will not use an environment.
|
2014-05-21 13:34:12 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `chef_license` (string) - As of Chef v15, Chef requires users to accept a
|
|
|
|
license. Defaults to `accept-silent` when `skip_install` is false and
|
|
|
|
`install_command` is unset. Possible values are `accept`,
|
|
|
|
`accept-silent` and `accept-no-persist`. For details see [Accepting the
|
|
|
|
Chef License](https://docs.chef.io/chef_license_accept.html).
|
2019-05-17 11:19:22 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
This is a [template engine](/docs/templates/engine.html). Therefore, you
|
|
|
|
may use user variables and template functions in this field.
|
2020-02-20 05:05:27 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `config_template` (string) - Path to a template that will be used for the
|
|
|
|
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.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `elevated_user` and `elevated_password` (string) - If specified, Chef will
|
|
|
|
be run with elevated privileges using the given Windows user. See the
|
|
|
|
[powershell](/docs/provisionders/powershell.html) provisioner for the full
|
|
|
|
details.
|
2018-12-13 05:25:12 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `encrypted_data_bag_secret_path` (string) - The path to the file containing
|
|
|
|
the secret for encrypted data bags. By default, this is empty, so no secret
|
|
|
|
will be available.
|
2015-09-29 14:52:49 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `execute_command` (string) - The command used to execute Chef. This has
|
|
|
|
various [configuration template variables](/docs/templates/engine.html)
|
|
|
|
available. See below for more information.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `guest_os_type` (string) - The target guest OS type, either "unix" or
|
|
|
|
"windows". Setting this to "windows" will cause the provisioner to use
|
|
|
|
Windows friendly paths and commands. By default, this is "unix".
|
2015-08-20 16:56:58 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `install_command` (string) - The command used to install Chef. This has
|
|
|
|
various [configuration template variables](/docs/templates/engine.html)
|
|
|
|
available. See below for more information.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `json` (object) - An arbitrary mapping of JSON that will be available as
|
|
|
|
node attributes while running Chef.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `knife_command` (string) - The command used to run Knife during node
|
|
|
|
clean-up. This has various [configuration template
|
|
|
|
variables](/docs/templates/engine.html) available. See below for more
|
|
|
|
information.
|
2016-06-14 18:18:08 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `node_name` (string) - The name of the node to register with the Chef
|
2020-03-23 20:02:12 -04:00
|
|
|
Server. This is optional and by default is `packer-{{uuid}}`.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `policy_group` (string) - The name of a policy group that exists on the
|
|
|
|
Chef server. `policy_name` must also be specified.
|
2018-01-31 16:08:25 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `policy_name` (string) - The name of a policy, as identified by the name
|
|
|
|
setting in a `Policyfile.rb` file. `policy_group` must also be specified.
|
2018-01-31 16:08:25 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `prevent_sudo` (boolean) - By default, the configured commands that are
|
|
|
|
executed to install and run Chef are executed with `sudo`. If this is true,
|
|
|
|
then the sudo will be omitted. This has no effect when guest_os_type is
|
|
|
|
windows.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `run_list` (array of strings) - The [run
|
|
|
|
list](http://docs.chef.io/essentials_node_object_run_lists.html) for Chef.
|
|
|
|
By default this is empty, and will use the run list sent down by the Chef
|
|
|
|
Server.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `server_url` (string) - The URL to the Chef server. This is required.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `skip_clean_client` (boolean) - If true, Packer won't remove the client
|
|
|
|
from the Chef server after it is done running. By default, this is false.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `skip_clean_node` (boolean) - If true, Packer won't remove the node from
|
|
|
|
the Chef server after it is done running. By default, this is false.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `skip_clean_staging_directory` (boolean) - If true, Packer won't remove the
|
|
|
|
Chef staging directory from the machine after it is done running. By
|
|
|
|
default, this is false.
|
2016-12-19 17:21:39 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `skip_install` (boolean) - If true, Chef will not automatically be
|
|
|
|
installed on the machine using the Chef omnibus installers.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `ssl_verify_mode` (string) - Set to "verify_none" to skip validation of
|
|
|
|
SSL certificates. If not set, this defaults to "verify_peer" which
|
|
|
|
validates all SSL certifications.
|
2016-04-01 15:35:05 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `trusted_certs_dir` (string) - This is a directory that contains additional
|
|
|
|
SSL certificates to trust. Any certificates in this directory will be added
|
|
|
|
to whatever CA bundle ruby is using. Use this to add self-signed certs for
|
|
|
|
your Chef Server or local HTTP file servers.
|
2018-01-12 17:53:49 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `staging_directory` (string) - This is the directory where all the
|
|
|
|
configuration of Chef by Packer will be placed. By default this is
|
|
|
|
"/tmp/packer-chef-client" when guest_os_type unix and
|
|
|
|
"\$env:TEMP/packer-chef-client" 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. By default the
|
|
|
|
provisioner will create and chmod 0777 this directory.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `client_key` (string) - Path to client key. If not set, this defaults to a
|
|
|
|
file named client.pem in `staging_directory`.
|
2015-04-09 02:19:52 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `validation_client_name` (string) - Name of the validation client. If not
|
|
|
|
set, this won't be set in the configuration and the default that Chef uses
|
|
|
|
will be used.
|
2014-04-26 14:05:08 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `validation_key_path` (string) - Path to the validation key for
|
|
|
|
communicating with the Chef Server. This will be uploaded to the remote
|
|
|
|
machine. If this is NOT set, then it is your responsibility via other means
|
|
|
|
(shell provisioner, etc.) to get a validation key to where Chef expects it.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `version` (string) - The version of Chef to be installed. By default this
|
|
|
|
is empty which will install the latest version of Chef.
|
2019-12-09 14:17:04 -05:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'provisioners/common-config.mdx'
|
2019-04-08 10:05:04 -04:00
|
|
|
|
2014-02-24 12:45:04 -05: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.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
|
|
|
The default value for the configuration template is:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```liquid
|
2014-02-24 12:45:04 -05:00
|
|
|
log_level :info
|
|
|
|
log_location STDOUT
|
|
|
|
chef_server_url "{{.ServerUrl}}"
|
2015-08-20 16:56:58 -04:00
|
|
|
client_key "{{.ClientKey}}"
|
2019-05-17 11:19:22 -04:00
|
|
|
chef_license "{{.ChefLicense}}"
|
2015-08-20 16:56:58 -04:00
|
|
|
{{if ne .EncryptedDataBagSecretPath ""}}
|
|
|
|
encrypted_data_bag_secret "{{.EncryptedDataBagSecretPath}}"
|
|
|
|
{{end}}
|
2015-06-25 16:03:24 -04:00
|
|
|
{{if ne .ValidationClientName ""}}
|
|
|
|
validation_client_name "{{.ValidationClientName}}"
|
|
|
|
{{else}}
|
2014-02-24 12:45:04 -05:00
|
|
|
validation_client_name "chef-validator"
|
2015-06-25 16:03:24 -04:00
|
|
|
{{end}}
|
2014-02-24 12:45:04 -05:00
|
|
|
{{if ne .ValidationKeyPath ""}}
|
|
|
|
validation_key "{{.ValidationKeyPath}}"
|
|
|
|
{{end}}
|
|
|
|
node_name "{{.NodeName}}"
|
2015-08-20 16:56:58 -04:00
|
|
|
{{if ne .ChefEnvironment ""}}
|
|
|
|
environment "{{.ChefEnvironment}}"
|
|
|
|
{{end}}
|
2018-01-31 16:08:25 -05:00
|
|
|
{{if ne .PolicyGroup ""}}
|
|
|
|
policy_group "{{.PolicyGroup}}"
|
|
|
|
{{end}}
|
|
|
|
{{if ne .PolicyName ""}}
|
|
|
|
policy_name "{{.PolicyName}}"
|
|
|
|
{{end}}
|
2015-08-20 16:56:58 -04:00
|
|
|
{{if ne .SslVerifyMode ""}}
|
|
|
|
ssl_verify_mode :{{.SslVerifyMode}}
|
2015-06-25 16:03:24 -04:00
|
|
|
{{end}}
|
2018-01-12 17:53:49 -05:00
|
|
|
{{if ne .TrustedCertsDir ""}}
|
|
|
|
trusted_certs_dir :{{.TrustedCertsDir}}
|
|
|
|
{{end}}
|
2014-02-24 12:45:04 -05:00
|
|
|
```
|
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
This template is a [configuration template](/docs/templates/engine.html) and
|
|
|
|
has a set of variables available to use:
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `ChefEnvironment` - The Chef environment name.
|
|
|
|
- `ChefLicense` - The Chef license acceptance value.
|
|
|
|
- `EncryptedDataBagSecretPath` - The path to the secret key file to decrypt
|
|
|
|
encrypted data bags.
|
|
|
|
- `NodeName` - The node name set in the configuration.
|
|
|
|
- `ServerUrl` - The URL of the Chef Server set in the configuration.
|
|
|
|
- `SslVerifyMode` - Whether Chef SSL verify mode is on or off.
|
|
|
|
- `TrustedCertsDir` - Path to dir with trusted certificates.
|
|
|
|
- `ValidationClientName` - The name of the client used for validation.
|
|
|
|
- `ValidationKeyPath` - Path to the validation key, if it is set.
|
2014-02-24 12:45:04 -05: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:
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```liquid
|
2014-02-24 12:45:04 -05:00
|
|
|
{{if .Sudo}}sudo {{end}}chef-client \
|
|
|
|
--no-color \
|
|
|
|
-c {{.ConfigPath}} \
|
|
|
|
-j {{.JsonPath}}
|
|
|
|
```
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
When guest_os_type is set to "windows", Packer uses the following command to
|
2015-08-20 16:56:58 -04:00
|
|
|
execute Chef. The full path to Chef is required because the PATH environment
|
2017-10-04 17:25:31 -04:00
|
|
|
variable changes don't immediately propagate to running processes.
|
2015-08-20 16:56:58 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```liquid
|
2015-08-20 16:56:58 -04:00
|
|
|
c:/opscode/chef/bin/chef-client.bat \
|
|
|
|
--no-color \
|
|
|
|
-c {{.ConfigPath}} \
|
|
|
|
-j {{.JsonPath}}
|
|
|
|
```
|
|
|
|
|
2018-10-26 20:02:51 -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
|
2015-07-22 22:31:00 -04:00
|
|
|
contain various template variables, defined below:
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -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 value of the `prevent_sudo` configuration.
|
2014-02-24 12:45:04 -05: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.
|
2014-02-24 12:45:04 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```text
|
2017-11-14 19:43:57 -05:00
|
|
|
curl -L https://omnitruck.chef.io/chef/install.sh | \
|
2014-02-24 12:45:04 -05:00
|
|
|
{{if .Sudo}}sudo{{end}} bash
|
|
|
|
```
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
When guest_os_type is set to "windows", Packer uses the following command to
|
2015-08-20 16:56:58 -04:00
|
|
|
install the latest version of Chef:
|
|
|
|
|
2020-03-18 18:46:47 -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"
|
|
|
|
```
|
|
|
|
|
2014-02-24 12:45:04 -05:00
|
|
|
This command can be customized using the `install_command` configuration.
|
2015-06-15 16:37:20 -04:00
|
|
|
|
2016-06-14 18:18:08 -04:00
|
|
|
## Knife Command
|
|
|
|
|
|
|
|
By default, Packer uses the following command (broken across multiple lines for
|
|
|
|
readability) to execute Chef:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```liquid
|
2016-06-14 18:18:08 -04:00
|
|
|
{{if .Sudo}}sudo {{end}}knife \
|
|
|
|
{{.Args}} \
|
|
|
|
{{.Flags}}
|
|
|
|
```
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
When guest_os_type is set to "windows", Packer uses the following command to
|
2016-06-14 18:18:08 -04:00
|
|
|
execute Chef. The full path to Chef is required because the PATH environment
|
2017-10-04 17:25:31 -04:00
|
|
|
variable changes don't immediately propagate to running processes.
|
2016-06-14 18:18:08 -04:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```liquid
|
2016-06-14 18:18:08 -04:00
|
|
|
c:/opscode/chef/bin/knife.bat \
|
|
|
|
{{.Args}} \
|
|
|
|
{{.Flags}}
|
|
|
|
```
|
|
|
|
|
|
|
|
This command can be customized using the `knife_command` configuration. As you
|
|
|
|
can see from the default value above, the value of this configuration can
|
|
|
|
contain various template variables, defined below:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
- `Args` - The command arguments that are getting passed to the Knife
|
|
|
|
command.
|
|
|
|
- `Flags` - The command flags that are getting passed to the Knife command..
|
|
|
|
- `Sudo` - A boolean of whether to `sudo` the command or not, depending on
|
|
|
|
the value of the `prevent_sudo` configuration.
|
2016-06-14 18:18:08 -04:00
|
|
|
|
2015-06-15 16:37:20 -04:00
|
|
|
## Folder Permissions
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
!> The `chef-client` provisioner will chmod the directory with your Chef
|
2018-10-26 20:02:51 -04:00
|
|
|
keys to 777. This is to ensure that Packer can upload and make use of that
|
|
|
|
directory. However, once the machine is created, you usually don't want to keep
|
|
|
|
these directories with those permissions. To change the permissions on the
|
2015-07-22 22:31:00 -04:00
|
|
|
directories, append a shell provisioner after Chef to modify them.
|
2015-08-31 22:54:18 -04:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
2018-04-03 09:29:51 -04:00
|
|
|
### Chef Client Local Mode - Simple
|
|
|
|
|
|
|
|
The following example shows how to run the `chef-client` provisioner in local
|
|
|
|
mode.
|
|
|
|
|
|
|
|
**Packer variables**
|
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
Set the necessary Packer variables using environment variables or provide a
|
|
|
|
[var file](/docs/templates/user-variables.html).
|
2018-04-03 09:29:51 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2018-04-03 09:29:51 -04:00
|
|
|
"variables": {
|
|
|
|
"chef_dir": "/tmp/packer-chef-client"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
**Setup the** `chef-client` **provisioner**
|
|
|
|
|
|
|
|
Make sure we have the correct directories and permissions for the `chef-client`
|
|
|
|
provisioner. You will need to bootstrap the Chef run by providing the necessary
|
|
|
|
cookbooks using Berkshelf or some other means.
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2018-04-03 09:29:51 -04:00
|
|
|
"provisioners": [
|
|
|
|
...
|
|
|
|
{ "type": "shell", "inline": [ "mkdir -p {{user `chef_dir`}}" ] },
|
|
|
|
{ "type": "file", "source": "./roles", "destination": "{{user `chef_dir`}}" },
|
|
|
|
{ "type": "file", "source": "./cookbooks", "destination": "{{user `chef_dir`}}" },
|
|
|
|
{ "type": "file", "source": "./data_bags", "destination": "{{user `chef_dir`}}" },
|
|
|
|
{ "type": "file", "source": "./environments", "destination": "{{user `chef_dir`}}" },
|
|
|
|
{ "type": "file", "source": "./scripts/install_chef.sh", "destination": "{{user `chef_dir`}}/install_chef.sh" },
|
|
|
|
{
|
|
|
|
"type": "chef-client",
|
|
|
|
"install_command": "sudo bash {{user `chef_dir`}}/install_chef.sh",
|
|
|
|
"server_url": "http://localhost:8889",
|
|
|
|
"config_template": "./config/client.rb.template",
|
|
|
|
"run_list": [ "role[testing]" ],
|
|
|
|
"skip_clean_node": true,
|
|
|
|
"skip_clean_client": true
|
|
|
|
}
|
|
|
|
...
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
And ./config/client.rb.template referenced by the above configuration:
|
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```ruby
|
2018-04-03 09:29:51 -04:00
|
|
|
log_level :info
|
|
|
|
log_location STDOUT
|
|
|
|
local_mode true
|
|
|
|
chef_zero.enabled true
|
|
|
|
ssl_verify_mode "verify_peer"
|
|
|
|
role_path "{{user `chef_dir`}}/roles"
|
|
|
|
data_bag_path "{{user `chef_dir`}}/data_bags"
|
|
|
|
environment_path "{{user `chef_dir`}}/environments"
|
|
|
|
cookbook_path [ "{{user `chef_dir`}}/cookbooks" ]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Chef Client Local Mode - Passing variables
|
2015-08-31 22:54:18 -04:00
|
|
|
|
2016-12-05 09:31:36 -05:00
|
|
|
The following example shows how to run the `chef-client` provisioner in local
|
2015-09-01 12:20:52 -04:00
|
|
|
mode, while passing a `run_list` using a variable.
|
2015-08-31 22:54:18 -04:00
|
|
|
|
|
|
|
**Local environment variables**
|
|
|
|
|
2018-10-12 08:43:38 -04:00
|
|
|
# Machine's Chef directory
|
2017-06-14 21:04:16 -04:00
|
|
|
export PACKER_CHEF_DIR=/var/chef-packer
|
|
|
|
# Comma separated run_list
|
|
|
|
export PACKER_CHEF_RUN_LIST="recipe[apt],recipe[nginx]"
|
2015-08-31 22:54:18 -04:00
|
|
|
|
|
|
|
**Packer variables**
|
|
|
|
|
2018-10-26 20:02:51 -04:00
|
|
|
Set the necessary Packer variables using environment variables or provide a
|
|
|
|
[var file](/docs/templates/user-variables.html).
|
2015-08-31 22:54:18 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2015-08-31 22:54:18 -04:00
|
|
|
"variables": {
|
|
|
|
"chef_dir": "{{env `PACKER_CHEF_DIR`}}",
|
|
|
|
"chef_run_list": "{{env `PACKER_CHEF_RUN_LIST`}}",
|
|
|
|
"chef_client_config_tpl": "{{env `PACKER_CHEF_CLIENT_CONFIG_TPL`}}",
|
|
|
|
"packer_chef_bootstrap_dir": "{{env `PACKER_CHEF_BOOTSTRAP_DIR`}}" ,
|
|
|
|
"packer_uid": "{{env `PACKER_UID`}}",
|
|
|
|
"packer_gid": "{{env `PACKER_GID`}}"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
**Setup the** `chef-client` **provisioner**
|
|
|
|
|
2015-09-01 12:20:52 -04:00
|
|
|
Make sure we have the correct directories and permissions for the `chef-client`
|
|
|
|
provisioner. You will need to bootstrap the Chef run by providing the necessary
|
|
|
|
cookbooks using Berkshelf or some other means.
|
2015-08-31 22:54:18 -04:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2020-03-18 18:46:47 -04:00
|
|
|
({
|
2015-08-31 22:54:18 -04:00
|
|
|
"type": "file",
|
|
|
|
"source": "{{user `packer_chef_bootstrap_dir`}}",
|
|
|
|
"destination": "/tmp/bootstrap"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "shell",
|
|
|
|
"inline": [
|
|
|
|
"sudo mkdir -p {{user `chef_dir`}}",
|
|
|
|
"sudo mkdir -p /tmp/packer-chef-client",
|
|
|
|
"sudo chown {{user `packer_uid`}}.{{user `packer_gid`}} /tmp/packer-chef-client",
|
|
|
|
"sudo sh /tmp/bootstrap/bootstrap.sh"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "chef-client",
|
|
|
|
"server_url": "http://localhost:8889",
|
|
|
|
"config_template": "{{user `chef_client_config_tpl`}}/client.rb.tpl",
|
|
|
|
"skip_clean_node": true,
|
|
|
|
"skip_clean_client": true,
|
|
|
|
"run_list": "{{user `chef_run_list`}}"
|
2020-03-18 18:46:47 -04:00
|
|
|
})
|
2015-08-31 22:54:18 -04:00
|
|
|
```
|