Managing a Node using Chef
Managing a Node using Chef
Updated: 03 September 2023
Overview
Chef typically comprises of three different parts
- A Workstation which is the computer that cookbooks are authored and administered from (This can be your daily PC with any OS)
- A Chef Server is the central repository for cookbooks as well as information about the nodes they manage
- A Node is any computer managed by a Chef server and has Chef installed on it (This can be any instance of Ubuntu 14.04)
For this section we will need to have all of the above set up
Set Up Your Workstation
Download Chef
You will first need to download the Chef for your workstation from here
Open Chef Workstation
On Windows open the Chef Workstation Powershell app (CW Powershell), on Mac and Ubuntu open a terminal as usual
Be sure to use CW Powershell for the remainder of steps being carried out on Windows
Create a Working Directory
We’ll use our learn-chef
directory that we set up earlier
Install Git
How do you not have this??
Verify SSH
If you need to connect to your Chef Server with SSH, verify that you have SSH installed by running ssh
in your terminal. For Windows an SSH client is included with Git and Chef Workstation
Install Chef Server
Install and Configure
On the server, create a file /tmp/install-chef-server.sh
with the following contents
Next make the script a binary with
And then run it
Configure Ports
Ensure that ports 22, 80, and 443 are exposed on the Chef Server - On VirtualBox I just used port forwarding to map these to my local 22, 80, and 443 ports
Configure the Workstation
kife
is the command line tool that provides the interface between the your Workstation and the Chef Server, knife
requires two files to authenticate with the Chef Server:
- An RSA Private Key - The Chef server holds the public part, the Workstation holds the private
- A
knife
config file, typically calledknife.rb
and contains information like the Chef Server’s URL, the location of the RSA Private key, and the default cookbook location
Both of these are usually located in a .chef
directory
knife
provides a a way for you to download the necessary files as a starter kit, but that resets all keys for all users in the account, hence we will do so manually by following the instructions here
Create an Organization
Do not do this now, the setup script already has configured this for us
We can create an organization with the chef-server-ctl org-create
command, the command has the following structure
Create a User
Do not do this now, the setup script already has configured this for us
Similar to the process above, use chef-server-ctl user-create
to create a user, this has the general structure of
Move the .pem
Files
Move the .pem
files we just created to our chef-repo
with the following command
Copy the Private Key to Workstation
Copy the chefadmin.pem
file to your Workstation’s learn-chef/.chef
directory
Create Knife Config File
Create a knife
config file learn-chef/.chef/knife.rb
and replace the chef_server_url
with your Chef server’s FQDN
Verify the Setup
From the learn-chef
directory, with CW Powershell (or bash on another OS) run the following commands