Setting up Open Chef Server and a Workstation

The quick and dirty way…

Prep work

For me, I stood up two Centos 6.5 instances in virtualbox. I did the basics of installing the EPEL repo, groupinstall of “Base” and “developer tools” in YUM, setup and configured a user for myself.

Create my user:

useradd -m -G wheel seth
passwd seth

Install EPEL repo:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

YUM Groupinstall:

sudo yum groupinstall base "developer tools"


Downloading the needed files

http://www.getchef.com/chef/install/

First we will install the server…

 

For the server

Pick which package you need here and download it to the “chef-server”

cd /opt
sudo wget "https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-server-11.0.12-1.el6.x86_64.rpm"
sudo rpm -ivh  chef-server-11.0.12-1.el6.x86_64.rpm
sudo chef-server-ctl reconfigure

This command will set up all of the required components, including Erchef, RabbitMQ, and PostgreSQL

 sudo chef-server-ctl test

 

For the Workstation

As root run the curl command supplied to you from the Chef Download page. For me it was…

curl -L https://www.opscode.com/chef/install.sh | bash

Once this completes do this to test the install and see the version number:

chef-client -v

Now install GIT…

yum install git

(This will install version 1.7.1-ish)

From here as my own user I went to my home directory and cloned down the Chef GIT repo:

git clone git://github.com/opscode/chef-repo.git

Next cd into the chef-repo dir and create your .chef folder. This folder will hold your authorization files in a few steps from now.

cd chef-repo
 mkdir .chef

Add your .chef to the .gitignore file so it and its contents will not be uploaded.

echo .chef >> .gitignore

Get the .pem files and knife.rb files
You will need to copy these files from the chefserver that you previously setup. These files essentially give you access to connect to the server via chef-client and with knife. For me the command run from my workstation was…

sudo scp root@192.168.1.152:/etc/chef-server/admin.pem /home/seth/chef-repo/.chef/admin.pem
sudo scp root@192.168.1.152:/etc/chef-server/chef-validator.pem /home/seth/chef-repo/.chef/chef-validator.pem

You then want to run the knife initial command to create the knife.rb file in your .chef folder. Unless you know the hostname of your server and the locations of your admin and chef-validator.pem files this step will fail. You also need to make sure that port 443 is open on your server. You can do that with this:

sudo iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
sudo service iptables save

Now do this:

knife configure --initial

Here is what my output looked like to give you an idea of what to expect:

[seth@chefworkstation001 .chef]$ knife configure --initial
 Overwrite /home/seth/.chef/knife.rb? (Y/N)y
 Please enter the chef server URL: [https://chefworkstation001.devopshomelab:443] https://192.168.1.152:443
 Please enter a name for the new user: [seth]
 Please enter the existing admin name: [admin]
 Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem] /home/seth/chef-repo/.chef/admin.pem
 Please enter the validation clientname: [chef-validator]
 Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] /home/seth/chef-repo/.chef/chef-validator.pem
 Please enter the path to a chef repository (or leave blank):
 Creating initial API user...
 Please enter a password for the new user:
 Created user[seth]
 Configuration file written to /home/seth/.chef/knife.rb

Once you successfully make it past this point you should be good to go. You can test your configuration and connectivity to your server by running the following two commands:

knife client list
knife user list

Now lets bootstrap our new chef workstation

On the server you will need to configure knife like we did on the client side so do:

sudo knife configure -i

You will see something similar to what we saw the firwst time we ran this. Here is my output…

WARNING: No knife configuration file found
Where should I put the config file? [/root/.chef/knife.rb]
Please enter the chef server URL: [https://chefserver.devopshomelab:443]
Please enter a name for the new user: [seth] chefserver
Please enter the existing admin name: [admin]
Please enter the location of the existing admin's private key: [/etc/chef-server/admin.pem]
Please enter the validation clientname: [chef-validator]
Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem]
Please enter the path to a chef repository (or leave blank):
Creating initial API user...
Please enter a password for the new user:
Created user[chefserver]
Configuration file written to /root/.chef/knife.rb

If you have everything configured correctly you can now bootstrap your workstation by running the following command:

sudo ./knife bootstrap 192.168.1.153 --sudo -x seth -N "chefworkstation001"

 

You should have successfully installed and configured a working Chef open server and workstation following these steps. If you have questions or comments please feel free to use the comment section below. As always you can also consult the official Chef documentation on this subject by going here:

SERVER: http://docs.opscode.com/install_server.html

WORKSTATION: http://docs.opscode.com/install_workstation.html

Also check out my other post about bootstrapping a node in your new Chef environment. HERE

Advertisements

RUNIT and the ruby syntax error

Ive been working on writing my own cookbook to standup a fully ready to run ELK (Elasticsearch,Logstash,Kibana) server on CentOS. In doing this I have run into a few minor issues of compatibility here and there but nothing major. Once thing that I did find that was particularly troublesome was an error when I was trying to knife up a cookbook for “runit”. Its one of the dependancies for the chef-kibana cookbook and it relys on the “yum-epel” cookbook. I was able to knife up the yum-epel cookbook just fine but when I tried the runit cookbook I hot an error that said:

[seth@localhost cookbooks]$ knife cookbook upload runit yum-epel
Uploading runit [1.5.10]
FATAL: Cookbook file test/spec/libraries/provider_runit_service_spec.rb has a ruby syntax error:
FATAL: /home/seth/chef/chef-repo/.chef/../cookbooks/runit/test/spec/libraries/provider_runit_service_spec.rb:62: syntax error, unexpected '}', expecting tASSOC
FATAL: { provider.load_current_resource }.should raise_error
FATAL:                                                                          ^

My first mistake was installing and using RVM for Ruby management from way before I installed Chef. RVM is too big and robust and handles too many things to try and make it play nice and only worry about managing ruby for me. I uninstalled that and went with RBENV. This is the recommended manager of Ruby from Chef anyways. Once I got rbenv setup and installed I installed ruby 1.9.3p545. I tried again with the knife upload and I still got the same thing. I decided that maybe my version of Chef needed to be updated. I was on 11.2. I reinstalled Chef and tried the knife again. No luck. Same error…thanks for playing, try again.

Now I take to Google to see if this is something unique to me or have I found some bug somewhere. I came across this page and even though it was a year old it did help me out some. https://github.com/rcbops/chef-cookbooks/issues/352 The fix came to me when I re-downloaded the runit cookbook from https://github.com/hw-cookbooks/runit instead of using the cookbook I downloaded directly from Chef Community. For some reason the version was off by one iteration.

[seth@localhost cookbooks]$ knife cookbook upload runit
Uploading runit [1.5.11]
Uploaded 1 cookbook.

Success. Theres not really a better explanation as to what really was wrong here but I do feel it had more to do with the ruby installation than anything else. If you come across this and figure something out please feel free to leave a comment below.

SSH and GitHub

When you create an account on Github.com you might not realize that you need to setup your SSH keys. Here is what I did to make that happen…

On my box I did ssh-keygen -t rsa  I answered with the default yes’…although not as secure, since this is just for practice Im not worried a ton about that aspect right now.

I then logged onto my github account and added my SSH key by going to account settings and then the SSH Key section. I copied my PUBLIC key content from my key located at ~/.ssh/id_rsa.pub and pasted it in the window forthe key content.

Once this was complete I ran ssh -vT git@github.com to make sure I could connect ok…

If successful you should see something like this…

 

[seth@lab001 DevOpsHomeLab]$ ssh -vT git@github.com
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [192.30.252.131] port 22.
debug1: Connection established.
debug1: identity file /home/seth/.ssh/identity type -1
debug1: identity file /home/seth/.ssh/id_rsa type 1
debug1: identity file /home/seth/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host ‘github.com’ is known and matches the RSA host key.
debug1: Found key in /home/seth/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/seth/.ssh/identity
debug1: Offering public key: /home/seth/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Hi sethfloydjr! You’ve successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2272, received 3032 bytes, in 0.1 seconds
Bytes per second: sent 25456.3, received 33971.6
debug1: Exit status 1