github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/website/source/docs/provisioners/chef-client.html.markdown (about)

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