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