github.com/aclaygray/packer@v1.3.2/website/source/docs/provisioners/chef-solo.html.md (about) 1 --- 2 description: | 3 The chef-solo Packer provisioner installs and configures software on machines 4 built by Packer using chef-solo. Cookbooks can be uploaded from your local 5 machine to the remote machine or remote paths can be used. 6 layout: docs 7 page_title: 'Chef Solo - Provisioners' 8 sidebar_current: 'docs-provisioners-chef-solo' 9 --- 10 11 # Chef Solo Provisioner 12 13 Type: `chef-solo` 14 15 The Chef solo Packer provisioner installs and configures software on machines 16 built by Packer using [chef-solo](https://docs.chef.io/chef_solo.html). 17 Cookbooks can be uploaded from your local machine to the remote machine or 18 remote paths can be used. 19 20 The provisioner will even install Chef onto your machine if it isn't already 21 installed, using the official Chef installers provided by Chef Inc. 22 23 ## Basic Example 24 25 The example below is fully functional and expects cookbooks in the "cookbooks" 26 directory relative to your working directory. 27 28 ``` json 29 { 30 "type": "chef-solo", 31 "cookbook_paths": ["cookbooks"] 32 } 33 ``` 34 35 ## Configuration Reference 36 37 The reference of available configuration options is listed below. No 38 configuration is actually required, but at least `run_list` is recommended. 39 40 - `chef_environment` (string) - The name of the `chef_environment` sent to the 41 Chef server. By default this is empty and will not use an environment 42 43 - `config_template` (string) - Path to a template that will be used for the 44 Chef configuration file. By default Packer only sets configuration it needs 45 to match the settings set in the provisioner configuration. If you need to 46 set configurations that the Packer provisioner doesn't support, then you 47 should use a custom configuration template. See the dedicated "Chef 48 Configuration" section below for more details. 49 50 - `cookbook_paths` (array of strings) - This is an array of paths to 51 "cookbooks" directories on your local filesystem. These will be uploaded to 52 the remote machine in the directory specified by the `staging_directory`. By 53 default, this is empty. 54 55 - `data_bags_path` (string) - The path to the "data\_bags" directory on your 56 local filesystem. These will be uploaded to the remote machine in the 57 directory specified by the `staging_directory`. By default, this is empty. 58 59 - `encrypted_data_bag_secret_path` (string) - The path to the file containing 60 the secret for encrypted data bags. By default, this is empty, so no secret 61 will be available. 62 63 - `environments_path` (string) - The path to the "environments" directory on 64 your local filesystem. These will be uploaded to the remote machine in the 65 directory specified by the `staging_directory`. By default, this is empty. 66 67 - `execute_command` (string) - The command used to execute Chef. This has 68 various [configuration template 69 variables](/docs/templates/engine.html) available. See 70 below for more information. 71 72 - `guest_os_type` (string) - The target guest OS type, either "unix" or 73 "windows". Setting this to "windows" will cause the provisioner to use 74 Windows friendly paths and commands. By default, this is "unix". 75 76 - `install_command` (string) - The command used to install Chef. This has 77 various [configuration template 78 variables](/docs/templates/engine.html) available. See 79 below for more information. 80 81 - `json` (object) - An arbitrary mapping of JSON that will be available as 82 node attributes while running Chef. 83 84 - `prevent_sudo` (boolean) - By default, the configured commands that are 85 executed to install and run Chef are executed with `sudo`. If this is true, 86 then the sudo will be omitted. This has no effect when guest\_os\_type is 87 windows. 88 89 - `remote_cookbook_paths` (array of strings) - A list of paths on the remote 90 machine where cookbooks will already exist. These may exist from a previous 91 provisioner or step. If specified, Chef will be configured to look for 92 cookbooks here. By default, this is empty. 93 94 - `roles_path` (string) - The path to the "roles" directory on your 95 local filesystem. These will be uploaded to the remote machine in the 96 directory specified by the `staging_directory`. By default, this is empty. 97 98 - `run_list` (array of strings) - The [run 99 list](https://docs.chef.io/run_lists.html) for Chef. By default this 100 is empty. 101 102 - `skip_install` (boolean) - If true, Chef will not automatically be installed 103 on the machine using the Chef omnibus installers. 104 105 - `staging_directory` (string) - This is the directory where all the 106 configuration of Chef by Packer will be placed. By default this is 107 "/tmp/packer-chef-solo" when guest\_os\_type unix and 108 "$env:TEMP/packer-chef-solo" when windows. This directory doesn't need to 109 exist but must have proper permissions so that the user that Packer uses is 110 able to create directories and write into this folder. If the permissions 111 are not correct, use a shell provisioner prior to this to configure it 112 properly. 113 - `version` (string) - The version of Chef to be installed. By default this is 114 empty which will install the latest version of Chef. 115 116 ## Chef Configuration 117 118 By default, Packer uses a simple Chef configuration file in order to set the 119 options specified for the provisioner. But Chef is a complex tool that supports 120 many configuration options. Packer allows you to specify a custom configuration 121 template if you'd like to set custom configurations. 122 123 The default value for the configuration template is: 124 125 ``` liquid 126 cookbook_path [{{.CookbookPaths}}] 127 ``` 128 129 This template is a [configuration 130 template](/docs/templates/engine.html) and has a set of 131 variables available to use: 132 133 - `ChefEnvironment` - The current enabled environment. Only non-empty if the 134 environment path is set. 135 - `CookbookPaths` is the set of cookbook paths ready to embedded directly into 136 a Ruby array to configure Chef. 137 - `DataBagsPath` is the path to the data bags folder. 138 - `EncryptedDataBagSecretPath` - The path to the encrypted data bag secret 139 - `EnvironmentsPath` - The path to the environments folder. 140 - `RolesPath` - The path to the roles folder. 141 142 ## Execute Command 143 144 By default, Packer uses the following command (broken across multiple lines for 145 readability) to execute Chef: 146 147 ``` liquid 148 {{if .Sudo}}sudo {{end}}chef-solo \ 149 --no-color \ 150 -c {{.ConfigPath}} \ 151 -j {{.JsonPath}} 152 ``` 153 154 When guest\_os\_type is set to "windows", Packer uses the following command to 155 execute Chef. The full path to Chef is required because the PATH environment 156 variable changes don't immediately propagate to running processes. 157 158 ``` liquid 159 c:/opscode/chef/bin/chef-solo.bat \ 160 --no-color \ 161 -c {{.ConfigPath}} \ 162 -j {{.JsonPath}} 163 ``` 164 165 This command can be customized using the `execute_command` configuration. As you 166 can see from the default value above, the value of this configuration can 167 contain various template variables, defined below: 168 169 - `ConfigPath` - The path to the Chef configuration file. 170 - `JsonPath` - The path to the JSON attributes file for the node. 171 - `Sudo` - A boolean of whether to `sudo` the command or not, depending on the 172 value of the `prevent_sudo` configuration. 173 174 ## Install Command 175 176 By default, Packer uses the following command (broken across multiple lines for 177 readability) to install Chef. This command can be customized if you want to 178 install Chef in another way. 179 180 ``` text 181 curl -L https://omnitruck.chef.io/install.sh | \ 182 {{if .Sudo}}sudo{{end}} bash -s --{{if .Version}} -v {{.Version}}{{end}} 183 ``` 184 185 When guest\_os\_type is set to "windows", Packer uses the following command to 186 install the latest version of Chef: 187 188 ``` text 189 powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install\" 190 ``` 191 192 This command can be customized using the `install_command` configuration.