Linux

How to install Chef Server and Chef Client on Ubuntu 20.04

How to install Chef Server and Chef Client on Ubuntu 20.04

Installing a Chef is a challenge, but with a little help, you can activate and run it in no time. Jack Wallen shows the way.

Chef is a configuration management tool to assist you in setting up machines on physical hardware, virtual machines, or in the cloud. Written in Ruby and Erlang, Chef uses domain-specific languages ​​to write system configuration recipes. With this recipe you can, by treating Infrastructure as Code, configure many machines at once.

Chef is used by people like Facebook, Etsy, Cheezburger, and Indiegogo, so it’s a proven solution.

I will guide you through the process of installing Server Chef and Client on Ubuntu 20.04. Recipes are made in Chef Client and then distributed through Chef Server. I will show the installation on Ubuntu Server 20.04.

You can always install the client on a desktop machine if you want – especially for cases where your Chef admin needs a GUI to work with it. For larger deployments, where you may have many admins and developers working with Chef, you will install one Server and several Clients.

What do you need

  • Two instances of Ubuntu 20.04 are running
  • A user with sudo privileges

How to install Server Chef

The first thing we will do is install Server Chef. To do this, enter your Ubuntu Server 20.04 instance and download the core server with the command:

wget https://packages.chef.io/files/stable/chef-server/13.1.13/ubuntu/18.04/chef-server-core_13.1.13-1_amd64.deb

After the file is downloaded, install the package with the command:

sudo dpkg -i chef-server-core_*.deb

After the installation is complete, start the Server Chef service with the command:

sudo chef-server-ctl reconfigure

Now, we need to create a new directory that will hold security keys. Do this with the command:

mkdir ~/.chef

Next, we create a new user, as well as a key file for that user. Issue an order:

sudo chef-server-ctl user-create USERNAME FNAME LNAME EMAIL 'PASSWORD' --filename ~/.chef/USERNAME.pem

Where:

  • USERNAME is the username for new users
  • FNAME / LNAME is the user’s first and last name
  • EMAIL is the new user’s email address
  • PASSWORD is a strong and unique password for new users

With new users created, it’s time to create an organization. At the same time, we will add new users to the admin and bill the admin security group. This is done with the command:

sudo chef-server-ctl org-create ORGNAME "ORGFULLNAME" --association_user USERNAME --filename ~/.chef/ORGNAME.pem

Where ORGNAME (which must be in all lowercase letters) is the name of the organization, ORGFULLNAME is the full name of the organization, and USERNAME is the new username you just created.

And that is for server installation.

How to install Chef Client

Enter your client machine and download the necessary files with the command:

wget https://packages.chef.io/files/stable/chef-workstation/20.6.62/debian/10/chef-workstation_20.6.62-1_amd64.deb

After the file download is complete, install the software with the command:

sudo dpkg -i chef-workstation*.deb

Next, create a repository on the client with the command:

chef generate repo chef-repo

Create a subdirectory in the repository, which will hold the blade configuration, with the command:

mkdir ~/chef-repo/.chef

Change to the newly created repository with the command:

cd ~/chef-repo

How to make an RSA key and copy it to the server

If you don’t already have an RSA key on the client machine, create it with the command:

ssh-keygen -b 4096

Upload a new key to the server with the command:

ssh-copy-id USER@SERVER

Where USER is the username that generates the keypair and SERVER is the server’s IP address.

How to copy PEM files from your server to your client

Next, we must copy the PEM file from the server to the client. This is done from the server with the command:

scp USER@CLIENTIP:~/.chef/*.pem ~/chef-repo/.chef/

Where USER is the username that generates the PEM file and CLIENTIP is the IP address of the client machine.

How to add version control

Now we will control the version into the mix, so you can easily track changes with your recipe book. If you have not installed Git on your client, do it with the command:

sudo apt-get install git -y

When the installation is complete, configure Git with the following two commands:

git config --global user.name NAME
git config --global user.email EMAIL

Where NAME is your name and EMAIL is your email address.

Add the .chef directory to gitignore with the command:

echo ".chef" > ~/chef-repo/.gitignore

Change it into the repository with the command:

cd ~/chef-repo

Add and commit files with the command:

git add .
git commit -m "Initial Commit"

How to make your first recipe book and configure the knife

The next step is to make your first cookbook with the command:

chef generate cookbook my_cookbook

Once done, you must create a knife configuration file with the command:

nano ~/chef-repo/.chef/config.rb

In that file, paste the following:

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                'USER'
client_key               "USER.pem"
validation_client_name   'ORGNAME-validator'
validation_key           "ORGNAME-validator.pem"
chef_server_url          'https://SERVER/organizations/ORGNAME'
cache_type               'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path            ["#{current_dir}/../cookbooks"]

Where:

  • USER is the username that generates the client key
  • ORGNAME is the name of the organization that you created
  • SERVER is the hostname or IP address of the Chef server

Save and close the file.

Change to the chef-repo directory with the command:

cd ~/chef-repo

Get the SSL file from the server with the command:

knife ssl fetch

How to bootstrap a node

The final step is to install and validate the client on the server. Before you do that, you need to edit the host file on the client machine with the command:

sudo nano /etc/hosts

In that file add the IP address / host name of your Chef server in the form:

192.168.1.17 eaonvm

Be sure to use your server’s IP address and hostname. Save and close the file.

Change to the .chef directory with the command:

cd ~/chef-repo/.chef

To bootstrap a node, run the command:

knife bootstrap SERVER -x USER -P PASSWORD --node-name NODE

Where:

  • SERVER is the hostname or IP address of the Chef server
  • USER is the user you have used
  • PASSWORD is the password for USER
  • NODE is the name of the node

This can be a little complicated here. If the bootstrap fails, it’s likely because of the way you created the PEM file. If you use a host name for PEM files (not IP addresses), you must use the host name for bootstrapping.

After bootstrapping is successful, you can verify with the command (run on client):

knife client list

You should see an ORG validator returned (where ORG is the name of the organization you created).

And that’s all. You are now ready to start creating cookbooks and use them to configure machines on your network.

Related posts

How to Install Anaconda on Ubuntu 20.04

Linux

How to Install OpenCV on Ubuntu 20.04

Linux

How to Set Up WireGuard VPN Server and Client on Ubuntu 20.04

Linux

How to install CMake on Ubuntu

Linux

How to Install TensorFlow on CentOS

Linux

How to install headless CAC Strapi Node.js

Abim

How to Install phpMyAdmin with Nginx and Let’s Encrypt SSL on Ubuntu 20.04 LTS

Linux

How to Make a Bootable Linux USB Drive Using Linux

Howto

How to Activate Snap Package Manager on Linux Mint 20

Linux