Day 42: Setting up a Chef Workstation

In last week’s post, Getting Started with Chef, we demonstrated how to setup a Chef Server, this week we’ll go over how to setup a Chef Workstation on Ubuntu 12.04.

Any queries or changes to your Chef Environment will be done from a Chef Workstation. Chef has recently released a new collection of Development Tools called the Chef Development Kit; however, throughout the rest of this series, we will focus mainly on the knife command for managing Chef resources.

 

Installing Chef on Ubuntu 12.04

The Guide below assumes that you have already installed a Basic Installation of Ubuntu 12.04 with networking configured and DNS working properly. If you need some more direction on how to do this, please review the section in last week’s post entitled, Basic Ubuntu Network Configuration Sample.

The first step is to install the revision control system, git. The reason for using git is so that we can manage our Chef Configuration later on using Github and manage it as code. Although we won’t be uploading any changes into a Github repository at this time, setting up a free account on Github will be required later.

 

Next, configure the global settings of git

 

Next, we are going to install Chef

 

Next, we are going to clone the basic Chef Repository into our home directory from Github

 

Next, create a directory in the chef-repo directory to store SSH Keys

 

Next, Log into the Web Interface or your Chef Server and click on the Clients section.Click on Edit, next to chef-validator. Put a check-box next to Private Key and click on Save Client. Copy the contents of the private key and then create a new file in the .chef directory called chef-validator.pem. Save the File and Close it.

Next click on the Users section. Click on the admin account and then click on Edit. Put a check-box next to Regenerate Private Key. Copy the contents of the private key and then create a new file in the .chef directory called admin.pem. Save the File and Close it.

On subsequent Chef Workstations, you can copy over the .pem files into the .chef directory from another existing Chef Workstation using scp.

 

When you are done and you list the contents of .chef directory, you should have two files:

 

Next, configure git to ignore the .chef directory so private keys are not exposed when we commit changes up into our Github repository later.

 

Add the following line to the bottom of the file and then save it.

 

Next, we need to commit changes to our local git repository and comment on what the change is we are making.

 

Next, configure your bash_profile to include the path to the Chef version of Ruby. This will prevent issues from occurring whereby the version of Ruby installed in Ubuntu isn’t the same as the version of Ruby used by Chef.

Open up your bash_profile file, if one doesn’t exist already, this will create one for you.

 

Add the following lines to the file and then save and exit.

 

Next, log out and log back in to your SSH Session and check your PATH variable by running the following command

 

Verify that your PATH Value looks similar to what is below and that the /opt/chef/embedded/bin directory is at the beginning of the Value.

 

 

Configuring the Knife Command

The knife command is the main utility you will use when you want to query nodes (Hosts) that are a part of your Chef Environment or if you want bootstrap a new Host (install the Chef client on a Host and add it to Chef).

Run the following command to start the initial configuration

 

Below is a list of questions that will be presented to you during the initial configuration along with the answers that should work for this example. Don’t worry if you mess up the first time, you can simply rerun the initial configuration again using the command you previously ran above.

Please note that the <user> that is listed below should be replaced by the actual user you are logged in as that you are using to configure the Chef Workstation.

 

Once the initial configuration is finished, change back to your chef-repo directory

 

Next, run the following knife command to verify that you have connectivity between your Chef Workstation and the Chef Server.

 

You should get back the following response

 

 

Conclusion

This week’s post has demonstrated how to install and configure a Chef Workstation and verify that it is able to communicate with your Chef Server. In next weeks post, we’ll demonstrate how to add a Host into Chef.

 

Previous Installments

100 Days of DevOps with PowerShell

 

 

 

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.