Friday, 17 October 2014

Set up Chef on Ubuntu Machine

Ubuntu + Chef + Errors

On  chef server(new ubuntu machine)

cd ~
Install the chef server or install from web site
=> wget

Install the package using terminal
=> sudo dpkg -i chef-server*

Run this command to confugre chef server on the machine
=> sudo chef-server-ctl reconfigure

Open browser (write https and ip of server)

Add default username and password.

On workstation(diiferent ubuntu machine)

update the system
=> sudo apt-get update

Install Git
=> sudo apt-get install git

Install Curl
=> sudo apt-get install curl

You can download the chef client from wesite and manually install this.
otherwise run
=> curl -L | sudo bash

Get the chef-repo from git
=> git clone

create .chef repository
=> mkdir ~/chef-repo/.chef

Copy the keys:

Now we will put the keys into .chef folder so open in browser put chef server url

Login and Tap on the Clients > edit(chef-validator) > chek the checkbox > save
It will generate a key so just copy the private key and paste in

create a chef-validator file in .chef folder
=> vim chef-validator.pem
paste the key

There should be no extra space
Now same for the Users > admin > edit > check checkbox  for regenerate the private key > save
It will generate a key so just copy the private key and paste in

create a chef-validator file in .chef folder
=> vim admin.pem
paste the key

run knife command
=> knife configure --initial

PASTE THE PATH ASKED BY OPETIONS LIKE FOR admin key path should be /home/vagrant/chef-repo/.chef/admnin.pem
same for the all

No need to commit the .chef folder so
=> vim ~/chef-repo/.gitignore

Add .chef in the end of the file


# Ignore Chef key files and secrets

run knife command to check if knife is configured or not
=> knife user list

if it gives error reconfigure the knife configuration

Client Node (another ubuntu instance) ip address(

now bootstrap to the clint using the following command
=> knife bootstrap -x username -P password -N name_for_node --sudo

If bootstraps success than you will find a node in chef-repo/nodes

Now chek client list
=> knife client list

Errors faced by me

While creating node
Error: RuntimeError: Please set EDITOR environment variable
export EDITOR=$(which vi)

ERROR: Failed to upload /home/vagrant/chef-repo/cookbooks/apt/recipes/default.rb
Chef-server redirects api clients between its components (in this case erchef and bookshelf). These redirects are based on the FQDN of the chef-server. If the server doesn't have a valid FQDN at install time, this can result in redirects to https://localhost:443.

One solution is to fix the FQDN on chef-server and run chef-server-ctl reconfigure.

Another solution is to set a few options in /etc/chef-server/chef-server.rb (I had to create this file) and then run chef-server-ctl reconfigure.

server_name = ""
api_fqdn server_name

nginx['url'] = "https://#{server_name}"
nginx['server_name'] = server_name
lb['fqdn'] = server_name
bookshelf['vip'] = server_name