From 0950eac8366c0a7dacf26f3bf6e4596bc4561abe Mon Sep 17 00:00:00 2001 From: Kevin Pettijohn Date: Mon, 31 Aug 2015 19:54:18 -0700 Subject: [PATCH 1/2] 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`}}" +} +``` From 3034e12e5a5e90419a525df9de5ee788f1ea6c80 Mon Sep 17 00:00:00 2001 From: Kevin Pettijohn Date: Tue, 1 Sep 2015 09:20:52 -0700 Subject: [PATCH 2/2] Pandoc formating --- .../provisioners/chef-client.html.markdown | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/website/source/docs/provisioners/chef-client.html.markdown b/website/source/docs/provisioners/chef-client.html.markdown index 984d52a94..6da0104d1 100644 --- a/website/source/docs/provisioners/chef-client.html.markdown +++ b/website/source/docs/provisioners/chef-client.html.markdown @@ -71,9 +71,9 @@ configuration is actually required. then the sudo will be omitted. - `run_list` (array of strings) - The [run - list](http://docs.chef.io/essentials_node_object_run_lists.html) - for Chef. By default this is empty, and will use the run list sent down by - the Chef Server. + list](http://docs.chef.io/essentials_node_object_run_lists.html) for Chef. + By default this is empty, and will use the run list sent down by the + Chef Server. - `server_url` (string) - The URL to the Chef server. This is required. @@ -186,23 +186,21 @@ directories, append a shell provisioner after Chef to modify them. ### 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. +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]" -... -``` + # 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). +Set the necessary Packer variables using environment variables or provide a [var +file](/docs/templates/user-variables.html). ``` {.liquid} "variables": { @@ -217,10 +215,9 @@ Set the necessary Packer variables using environment variables or provide a **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. +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} {