From 0950eac8366c0a7dacf26f3bf6e4596bc4561abe Mon Sep 17 00:00:00 2001 From: Kevin Pettijohn Date: Mon, 31 Aug 2015 19:54:18 -0700 Subject: [PATCH] Add a chef-client local mode example * Configure the `chef-client` provisioner for local mode * Provide an example run_list --- .../provisioners/chef-client.html.markdown | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/website/source/docs/provisioners/chef-client.html.markdown b/website/source/docs/provisioners/chef-client.html.markdown index e655a4622..984d52a94 100644 --- a/website/source/docs/provisioners/chef-client.html.markdown +++ b/website/source/docs/provisioners/chef-client.html.markdown @@ -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`}}" +} +```