How to setup a Chef Server – Hosted environment

How to setup a Chef Server – Hosted environment


Purpose – Setting up Workstation where Chef recipes and cookbooks can be prepared and manage them using Hosted chef server.

Pre-requisites
Linux system – desktop1.example.com

Step1: Sign-up for Hosted chef

URL – https://manage.chef.io/signup/

Step2: Login to Chef management console

URL – https://manage.chef.io/login

Step3: Create a New Organization

GoTo – Organizations – Create
Provide – Full Name and Short Name

Step4: Setup .chef directory

Here we are going to setup our workstation to communicate with the Hosted Chef server, which was setup in step 2

About Knife, command line utility
This tool is used  as an interface between workstation and Chef server
This tool is used for uploading the cookbooks to chef server and work with nodes
This tool requires two files to authentication with chef server
RSA private key of the chef user
Knife.rb configuration file downloaded from chef server

Generate knife configuration file
Sign in to https://manage.chef.io/login.
From the Administration tab, select your organization.
From the menu on the left, select Generate Knife Config and save the file content to knife.rb below.

[root@desktop1 chefspace]# pwd
/home/student/Middleware/Source/chefspace
[root@desktop1 chefspace]# mkdir .chef
[root@desktop1 chefspace]# cd .chef/
[root@desktop1 .chef]# vi knife.rb

Generate RSA private key
Sign in to https://manage.chef.io/.
From the Administration tab, select Users from the menu on the left.
Select your user name, select Reset key from the menu on the left, download the RSA private key and save the content to <username>.pem file.

[root@desktop1 chefspace]# pwd
/home/student/Middleware/Source/chefspace
[root@desktop1 chefspace]# mkdir .chef
[root@desktop1 chefspace]# cd .chef/
[root@desktop1 .chef]# vi <username>.pem
[root@desktop1 .chef]# ls -ltr
total 8
-rw-r–r–. 1 root root  427 Jun  5 00:56 knife.rb
-rw-r–r–. 1 root root 1679 Jun  5 00:58 <username>.pem

[root@desktop1 .chef]# knife ssl check
Connecting to host api.chef.io:443
Successfully verified certificates from `api.chef.io’

At this point, our workstation is setup and communicating with the Hosted Chef server.
Below we will now try to upload a cookbook to the hosted chef server.

Step5: Get the learn_chef_httpd cookbook from github

[root@desktop1 chefspace]# pwd
/home/student/Middleware/Source/chefspace
[root@desktop1 chefspace]# ls -ahl
total 0
drwxr-xr-x. 3 root root 18 Jun  5 00:53 .
drwxr-xr-x. 3 root root 22 Jun  5 00:36 ..
drwxr-xr-x. 2 root root 43 Jun  5 00:58 .chef
[root@desktop1 chefspace]# mkdir cookbooks
[root@desktop1 chefspace]# cd cookbooks/
[root@desktop1 cookbooks]# git clone https://github.com/learn-chef/learn_chef_httpd.git
Cloning into ‘learn_chef_httpd’…
remote: Counting objects: 93, done.
remote: Total 93 (delta 0), reused 0 (delta 0), pack-reused 93
Unpacking objects: 100% (93/93), done.


Step6: Upload the cookbook to chef hosted server

[root@desktop1 cookbooks]# knife cookbook upload learn_chef_httpd
Uploading learn_chef_httpd [0.1.0]
Uploaded 1 cookbook.

Step7: List cookbooks present on chef hosted server

[root@desktop1 cookbooks]# knife cookbook list
learn_chef_httpd   0.1.0

Hope you enjoyed reading this article. Thank you.