Unattended chef client installation

chef

Has anyone tried performing an unattended chef client install – installing chef client from the node itself?

There is not much information provided in the documentation. Also, I don't want chef-solo but chef-client on the node.

Best Answer

It isn't clear from your question which OS you are doing this on and if you are doing it in a stand-alone or chef server environment.

Here are two options for stand-alone install of chef-client:

Omnibus installer

curl -L https://www.chef.io/chef/install.sh | sudo bash

or for a specific version

curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -v 12.0.2

Package install

Example for Ubuntu:

wget https://opscode-omnibus-packages.s3.amazonaws.com/debian/6/x86_64/chef_12.5.1-1_amd64.deb
sudo dpkg -i chef_12.5.1-1_amd64.deb

Bootstrap

Knife bootstrap will install the chef-client on a node in a chef server environment. Bootstrap uses the omnibus installer and then copies the required client configuration from the server.

knife bootstrap 123.45.6.789 -x username -P password --sudo

Unattended Bootstrap

The chef-client can be installed using an unattended bootstrap. This allows the chef-client to be installed from itself, without using SSH. For example, machines are often created using environments like AWS Auto Scaling, AWS CloudFormation, Rackspace Auto Scale, and PXE. In this scenario, using tooling for attended, single-machine installs like knife bootstrap or knife CLOUD_PLUGIN create is not practical because the machines are created automatically and someone cannot always be on-hand to initiate the bootstrap process.

When the chef-client is installed using an unattended bootstrap, remember that the chef-client:

  • Must be able to authenticate to the Chef server
  • Must be able to configure a run-list
  • May require custom attributes, depending on the cookbooks that are being used
  • Must be able to access the chef-validator.pem so that it may create a new identity on the Chef server
  • Must have a unique node name; the chef-client will use the FQDN for the host system by default

When the chef-client is installed using an unattended bootstrap, it is typically built into an image that starts the chef-client on boot. The type of image used depends on the platform on which the unattended bootstrap will take place.

Use settings in the client.rb file—chef_server_url, http_proxy, and so on—to ensure that configuration details are built into the unattended bootstrap process.

A node’s initial run-list is specified using a JSON file on the host system. When running the chef-client as an executable, use the -j option to tell the chef-client which JSON file to use. For example:

chef-client -j /etc/chef/file.json --environment _default

where file.json is similar to:

{
  "resolver": {
    "nameservers": [ "10.0.0.1" ],
    "search":"int.example.com"
  },
  "run_list": [ "recipe[resolver]" ]
}

You may also want to check out Provision and Bootstrap AWS instances with Chef

Related Topic