Add a chef-client local mode example

* Configure the `chef-client` provisioner for local mode
* Provide an example run_list
This commit is contained in:
Kevin Pettijohn 2015-08-31 19:54:18 -07:00
parent 17cea4fa95
commit 0950eac836
1 changed files with 65 additions and 0 deletions

View File

@ -181,3 +181,68 @@ 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
directories, append a shell provisioner after Chef to modify them.
## Examples
### Chef Client Local Mode
The following example shows how to run the `chef-cilent` provisioner in
local mode, while passing a `run_list` using a variable.
**Local environment variables**
```
# Machines Chef directory
export PACKER_CHEF_DIR=/var/chef-packer
# Comma separated run_list
export PACKER_CHEF_RUN_LIST="recipe[apt],recipe[nginx]"
...
```
**Packer variables**
Set the necessary Packer variables using environment variables or provide a
[var file](/docs/templates/user-variables.html).
``` {.liquid}
"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**
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.
``` {.liquid}
{
"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`}}"
}
```