Why I Looked Into Chef
Managing servers one by one doesn’t scale. I set up Chef to store server configs as code — a Chef server, a workstation where I write recipes, and a node that pulls its config automatically.
Note: I did this on Ubuntu 18.04 using .deb packages and apt.
Chef Server
The Chef server acts as the central hub for all workstations and nodes under Chef management. Configuration changes made on workstations are pushed to the Chef server, where they are pulled by nodes using chef-client to apply the configurations.
Install the Chef Server
Download the latest Chef server core:
wget https://packages.chef.io/files/stable/chef-server/13.1.13/ubuntu/18.04/chef-server-core_13.1.13-1_amd64.debInstall the server:
sudo dpkg -i chef-server-core_*.debStart the Chef server services:
sudo chef-server-ctl reconfigure
Create a Chef User and Organization
To link workstations and nodes to the Chef server, create an administrator and organization with associated RSA private keys.
Create a
.chefdirectory to store the keys:mkdir ~/.chefCreate a user with
chef-server-ctl, replacing placeholders with your details:sudo chef-server-ctl user-create USER_NAME FIRST_NAME LAST_NAME EMAIL 'PASSWORD' --filename ~/.chef/USER_NAME.pemList all users:
sudo chef-server-ctl user-listCreate an organization and associate the user:
sudo chef-server-ctl org-create ORG_NAME "ORG_FULL_NAME" --association_user USER_NAME --filename ~/.chef/ORG_NAME.pemList all organizations:
sudo chef-server-ctl org-list
With the Chef server installed and RSA keys generated, the workstation can now be configured.
Chef Workstations
The Chef workstation is where recipes, cookbooks, attributes, and configurations are managed. It can be a local machine or a remote server.
Setting Up a Workstation
Download the latest Chef Workstation:
wget https://packages.chef.io/files/stable/chef-workstation/0.2.43/ubuntu/18.04/chef-workstation_0.2.43-1_amd64.debInstall Chef Workstation:
sudo dpkg -i chef-workstation_*.debCreate your Chef repository:
chef generate repo chef-repoEnsure that your workstation’s
/etc/hostsfile correctly maps IP addresses to the Chef server and workstation hostnames.Create a
.chefsubdirectory withinchef-repoto store authentication files:mkdir ~/chef-repo/.chef cd chef-repo
Add the RSA Private Keys
Authentication between the Chef server and workstations/nodes is performed using public-key encryption. Copy the RSA private keys from the Chef server to the workstation.
Generate an RSA key pair on the workstation (if not already available):
ssh-keygen -b 4096Upload the workstation’s public key to the Chef server:
ssh-copy-id example_user@192.0.2.0Copy the
.pemfiles from the Chef server to the workstation:scp example_user@192.0.2.0:~/.chef/*.pem ~/chef-repo/.chef/Confirm the files were copied:
ls ~/chef-repo/.chef
Bootstrap a Node
Bootstrapping a node installs the Chef client and validates the node, allowing it to pull and apply configurations from the Chef server.
Update the
/etc/hostsfile on the node to correctly identify the node, Chef server, and workstation.From the workstation, navigate to the
.chefdirectory:cd ~/chef-repo/.chefBootstrap the node:
knife bootstrap 192.0.2.0 -x root -P password --node-name nodenameVerify the node has been bootstrapped:
knife client listAdd the bootstrapped node to the workstation’s
/etc/hostsfile.
For more detailed information, refer to the Linode guide.