How to Install & Configure Chef on ubuntu 20.04

Chef is a free & open source devops software & used for automation.It handles by infrastructure transforming into code.It provides facilities like how managed the infrastructure, deployment, or configuration all the network.We can deploy or manage resources on multiple servers or nodes.We can create & test the code on a workstation before the deployment on any other environment.

Prerequisites

  • sudo privileges.
  • We needs Two Ubuntu 20.04 system: master server & Client server.

Install Chef on ubuntu

Update the system.

apt-get update

Set the Hostname.

hostnamectl set-hostname host-name

Open the host file.

vim /etc/hosts

Add the following line.

server-ip host-name

Install the required packages.

apt-get install curl wget gnupg2

Download the Chef package.

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

Install the packages.

dpkg -i chef-server-core_13.1.13-1_amd64.deb

Configure the Chef server.

chef-server-ctl reconfigure

Here is the command output.

+---------------------------------------------+
Chef License Acceptance

Before you can continue, 3 product licenses
must be accepted. View the license at
https://www.chef.io/end-user-license-agreement/

Licenses that need accepting:
* Chef Infra Server
* Chef Infra Client
* Chef InSpec

Do you accept the 3 product licenses (yes/no)?

> 

Type Yes.

Once the configure the server is done,the output is:

Running handlers:
Running handlers complete
Chef Infra Client finished, 482/1032 resources updated in 03 minutes 28 seconds
Chef Server Reconfigured!

Create an Administrator Account.

Create a directory.

mkdir ~/.chef_key

Run the following command.

chef-server-ctl user-create user-name user-full-name User email-id 'user-password' 
--filename ~/.chef_key/example.pem

Create an Organization.

chef-server-ctl org-create organization-name "organization-full-name" 
--association_user user-name --filename ~/.chef_key/example-org.pem

List the Key.

ls ~/.chef_key/

Install Chef Web Management interface.

Install the Chef manage.

chef-server-ctl install chef-manage

Configure the Chef server and Chef manage.

chef-server-ctl reconfigure
chef-manage-ctl reconfigure

Type Yes.

Press any key to continue.
Type 'yes' to accept the software license agreement or anything else to cancel.

Install Chef Client on Client server.

Download the Chef workstation package:

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

Install the downloaded package.

dpkg -i chef-workstation_20.6.62-1_amd64.deb

Create a Chef repo.

chef generate repo chef-repo

Here is the command output.

 

+---------------------------------------------+
            Chef License Acceptance

Before you can continue, 3 product licenses
must be accepted. View the license at
https://www.chef.io/end-user-license-agreement/

Licenses that need accepting:
  * Chef Workstation
  * Chef Infra Client
  * Chef InSpec

Do you accept the 3 product licenses (yes/no)?

> 

 

Type Yes to accept the Licenses.The output is:

+---------------------------------------------+
Generating Chef Infra repo chef-repo
- Ensuring correct Chef Infra repo file content

Your new Chef Infra repo is ready! Type `cd chef-repo` to enter it.

List all files.

ls chef-repo

Here is the command output.

LICENSE  README.md  chefignore  cookbooks  data_bags  policyfiles

Create a .chef directory.We can store all Knife configuration file and the .pem files in .chef directory.

mkdir chef-repo/.chef

Create an SSH key.

ssh-keygen -b 4096

Here is the command output.

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:QNRvekbAmh3Nx55MTPnpH85y7RciwgMi29bsQhZdbbA
The key's randomart image is:
+---[RSA 4096]----+
|     .oo +o+..   |
|     .  =.+o*    |
|      o+.E.= o . |
|   . oo+. + + o  |
|    + = S+   .   |
|   . = o.+o. ..o |
|    + .  oo . +.+|
|     . .     . ++|
|      .       o.o|
+----[SHA256]-----+

Copy the created key to the Chef server.

ssh-copy-id [email protected]

Copy all .pem files from the Chef server to the client server.

scp [email protected]:~/.chef_key/*.pem ~/chef-repo/.chef/

Configure the Knife and Generate Cookbook.

Go to chef-repo directory.

cd ~/chef-repo

Create a cookbook.

chef generate cookbook new_cookbook

Create a new Knife configuration file:

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

Add the given below lines:Provide organization name and username.

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

Open the host file.

vim  /etc/hosts

Add the following lines.Provide the chef server ip.

server-ip host-name

Fetch the SSL certificate.

cd ~/chef-repo
knife ssl fetch

Verify the SSL.

knife ssl check

Install the Chef client on the node

Go to .chef directory on client-server.

cd ~/chef-repo/.chef

Bootstrap the client.

knife bootstrap host-name -x root -P rootpassword --node-name example

List all nodes.

knife client list

Access Chef Manage interface.

http://server-ip/login

Here is the output.

Provide the user-name & password.

 

Fig 1

Now Chef is ready.

 

Leave a Reply