Bootstrap EC2 with chef

From open-voip.org

Jump to: navigation, search

install chef

curl -L https://www.opscode.com/chef/install.sh | bash /dev/stdin -v 11.4.4

install the AWS CLI tool:

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

copy the the chef files from the

sudo su
mkdir /etc/chef
cd 
cd /etc/chef
aws s3 cp s3://deltathree-chef/knife.rb .
aws s3 cp s3://deltathree-chef/sportzone-validator.pem .

bootstrap the instance with the server with a specific role:

sudo chef-client -c /etc/chef/knife.rb -o 'role[webserver]'

cleanup the node from chef server when terminating

aws s3 cp s3://deltathree-chef/K99unregisterchef /etc/rc6.d/
sudo chmod +x /etc/rc6.d/K99unregisterchef

tips

example of knife.rb (or client.rb file)

# See http://docs.getchef.com/config_rb_knife.html for more information on knife configuration options
current_dir = File.dirname(__FILE__)
log_level                :auto
log_location             "/tmp/first-chef-client-run.log"
node_name                ENV['HOSTNAME']
client_key               "#{current_dir}/#{ENV['HOSTNAME']}.pem"
validation_client_name   "sportzone-validator"
validation_key           "#{current_dir}/sportzone-validator.pem"
chef_server_url          "https://api.opscode.com/organizations/sportzone"
#environment             "%%environment%%"

example of K99unregisterchef file

#!/bin/bash
cd /etc/chef
knife node delete $HOSTNAME -y

All the script to set in the Instance user data

#!/bin/bash
curl -L https://www.opscode.com/chef/install.sh | bash /dev/stdin -v 11.4.4
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
mkdir /etc/chef
cd 
cd /etc/chef
aws s3 cp s3://deltathree-chef/knife.rb .
aws s3 cp s3://deltathree-chef/sportzone-validator.pem .
chef-client -c /etc/chef/knife.rb -o 'role[webserver]'
aws s3 cp s3://deltathree-chef/K99unregisterchef /etc/rc6.d/
chmod +x /etc/rc6.d/K99unregisterchef
Personal tools