Centos6 : Chef Node Creation

I thought I'd share the scripts I use to take a fresh Centos6 install and have it configured to work with a Chef server. Maybe its not as easy as when running in a virtualized environment, but it saves plenty of time.

On the new node I run the setup_client.sh script which calls in the end client_gen.sh on the Chef server once everything is installed on the node. I left the version numbers for Ruby and Chef in the script so you know what versions I've tested this with.

setup_client.sh

#!/bin/bash  
CHEF_IP=XXX.XXX.XXX.XXX  
CHEF=http://$CHEF_IP:4000  
CHEF_USER=XXXXX  
NODE=XXXXXXXX  
RUBY_VSN=1.3.7  
CHEF_VSN=0.9.16  
  
sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm  
  
sudo yum update  
  
sudo yum install ruby ruby-shadow ruby-ri ruby-rdoc gcc gcc-c++ ruby-devel ruby-static  
  
cd /tmp  
wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBY_VSN.tgz  
tar zxf rubygems-$RUBY_VSN.tgz  
cd rubygems-$RUBY_VSN  
sudo ruby setup.rb --no-format-executable  
  
sudo gem install chef -v $CHEF_VSN   
  
mkdir ~/.chef  
  
cat > ~/.chef/knife.rb <<EOF log_level :info log_location STDOUT node_name '$NODE' client_key '/home/$USER/.chef/$NODE.pem' validation_client_name 'chef-validator' validation_key '/etc/chef/validation.pem' chef_server_url '$CHEF' cache_type 'BasicFile' cache_options( :path => '/home/$USER/.chef/checksums' ) EOF  
  
ssh-keygen -t rsa  
ssh-copy-id -i ~/.ssh/id_rsa.pub $CHEF_IP  
  
ssh $CHEF_IP "yes | knife client delete $NODE"  
ssh $CHEF_IP "yes | /home/$CHEF_USER/client_gen.sh $NODE"  
scp $CHEF_IP:/tmp/$NODE ~/.chef/$NODE.pem

client_gen.sh

#!/bin/bash  
knife client create $1 -n -a -f /tmp/$1  
knife node create $1 --no-editor
Centos6 : Chef Node Creation
Share this