Pages

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
 => http://www.getchef.com/chef/install/
or
cli
=> wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef-server_11.0.10-1.ubuntu.12.04_amd64.deb

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)
https://server_domain_or_IP

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.
http://www.getchef.com/chef/install/
otherwise run
=> curl -L https://www.opscode.com/chef/install.sh | sudo bash

Get the chef-repo from git
=> git clone https://github.com/opscode/chef-repo.git

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
https://server_domain_or_IP

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

.rake_test_cache

###
# Ignore Chef key files and secrets
###
.chef/*.pem
.chef/encrypted_data_bag_secret
.chef

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(22.2.22.1)

now bootstrap to the clint using the following command
=> knife bootstrap 22.2.22.1 -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
Sol:
export EDITOR=$(which vi)

ERROR: Failed to upload /home/vagrant/chef-repo/cookbooks/apt/recipes/default.rb
Sol:
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 = "192.168.114.11"
api_fqdn server_name

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

No comments:

Post a Comment