github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/website/source/docs/provisioners/chef-client.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "Chef-Client Provisioner" 4 --- 5 6 # Chef Client Provisioner 7 8 Type: `chef-client` 9 10 The Chef Client provisioner installs and configures software on machines built 11 by Packer using [chef-client](http://docs.opscode.com/chef_client.html). 12 Packer configures a Chef client to talk to a remote Chef Server to 13 provision the machine. 14 15 The provisioner will even install Chef onto your machine if it isn't already 16 installed, using the official Chef installers provided by Opscode. 17 18 ## Basic Example 19 20 The example below is fully functional. It will install Chef onto the 21 remote machine and run Chef client. 22 23 <pre class="prettyprint"> 24 { 25 "type": "chef-client", 26 "server_url": "http://mychefserver.com:4000/" 27 } 28 </pre> 29 30 ## Configuration Reference 31 32 The reference of available configuration options is listed below. No 33 configuration is actually required, but `node_name` is recommended 34 since it will allow the provisioner to clean up the node/client. 35 36 * `config_template` (string) - Path to a template that will be used for 37 the Chef configuration file. By default Packer only sets configuration 38 it needs to match the settings set in the provisioner configuration. If 39 you need to set configurations that the Packer provisioner doesn't support, 40 then you should use a custom configuration template. See the dedicated 41 "Chef Configuration" section below for more details. 42 43 * `execute_command` (string) - The command used to execute Chef. This has 44 various [configuration template variables](/docs/templates/configuration-templates.html) 45 available. See below for more information. 46 47 * `install_command` (string) - The command used to install Chef. This has 48 various [configuration template variables](/docs/templates/configuration-templates.html) 49 available. See below for more information. 50 51 * `json` (object) - An arbitrary mapping of JSON that will be available as 52 node attributes while running Chef. 53 54 * `node_name` (string) - The name of the node to register with the Chef 55 Server. This is optional and by defalt is empty. If you don't set this, 56 Packer can't clean up the node from the Chef Server using knife. 57 58 * `prevent_sudo` (boolean) - By default, the configured commands that are 59 executed to install and run Chef are executed with `sudo`. If this is true, 60 then the sudo will be omitted. 61 62 * `run_list` (array of strings) - The [run list](http://docs.opscode.com/essentials_node_object_run_lists.html) 63 for Chef. By default this is empty, and will use the run list sent 64 down by the Chef Server. 65 66 * `server_url` (string) - The URL to the Chef server. This is required. 67 68 * `skip_clean_client` (boolean) - If true, Packer won't remove the client 69 from the Chef server after it is done running. By default, this is false. 70 71 * `skip_clean_node` (boolean) - If true, Packer won't remove the node 72 from the Chef server after it is done running. By default, this is false. 73 This will be true by default if `node_name` is not set. 74 75 * `skip_install` (boolean) - If true, Chef will not automatically be installed 76 on the machine using the Opscode omnibus installers. 77 78 * `staging_directory` (string) - This is the directory where all the configuration 79 of Chef by Packer will be placed. By default this is "/tmp/packer-chef-client". 80 This directory doesn't need to exist but must have proper permissions so that 81 the SSH user that Packer uses is able to create directories and write into 82 this folder. If the permissions are not correct, use a shell provisioner 83 prior to this to configure it properly. 84 85 * `validation_client_name` (string) - Name of the validation client. If 86 not set, this won't be set in the configuration and the default that Chef 87 uses will be used. 88 89 * `validation_key_path` (string) - Path to the validation key for communicating 90 with the Chef Server. This will be uploaded to the remote machine. If this 91 is NOT set, then it is your responsibility via other means (shell provisioner, 92 etc.) to get a validation key to where Chef expects it. 93 94 ## Chef Configuration 95 96 By default, Packer uses a simple Chef configuration file in order to set 97 the options specified for the provisioner. But Chef is a complex tool that 98 supports many configuration options. Packer allows you to specify a custom 99 configuration template if you'd like to set custom configurations. 100 101 The default value for the configuration template is: 102 103 ``` 104 log_level :info 105 log_location STDOUT 106 chef_server_url "{{.ServerUrl}}" 107 validation_client_name "chef-validator" 108 {{if ne .ValidationKeyPath ""}} 109 validation_key "{{.ValidationKeyPath}}" 110 {{end}} 111 {{if ne .NodeName ""}} 112 node_name "{{.NodeName}}" 113 {{end}} 114 ``` 115 116 This template is a [configuration template](/docs/templates/configuration-templates.html) 117 and has a set of variables available to use: 118 119 * `NodeName` - The node name set in the configuration. 120 * `ServerUrl` - The URL of the Chef Server set in the configuration. 121 * `ValidationKeyPath` - Path to the validation key, if it is set. 122 123 ## Execute Command 124 125 By default, Packer uses the following command (broken across multiple lines 126 for readability) to execute Chef: 127 128 ``` 129 {{if .Sudo}}sudo {{end}}chef-client \ 130 --no-color \ 131 -c {{.ConfigPath}} \ 132 -j {{.JsonPath}} 133 ``` 134 135 This command can be customized using the `execute_command` configuration. 136 As you can see from the default value above, the value of this configuration 137 can contain various template variables, defined below: 138 139 * `ConfigPath` - The path to the Chef configuration file. 140 file. 141 * `JsonPath` - The path to the JSON attributes file for the node. 142 * `Sudo` - A boolean of whether to `sudo` the command or not, depending on 143 the value of the `prevent_sudo` configuration. 144 145 ## Install Command 146 147 By default, Packer uses the following command (broken across multiple lines 148 for readability) to install Chef. This command can be customized if you want 149 to install Chef in another way. 150 151 ``` 152 curl -L https://www.opscode.com/chef/install.sh | \ 153 {{if .Sudo}}sudo{{end}} bash 154 ``` 155 156 This command can be customized using the `install_command` configuration.