Chef Bootstrapping on Debia/Ubuntu EC2 AMI's

The easiest way is to use a user-data shell script. Ubuntu/Debian images on EC2 can use user-data scripts and run them on AMI boot.
#! /bin/sh
role="YOUR ROLE HERE"
chef_server="http://YOURCHEFSERVER"

apt-get update
APT_GET="env DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get -q -y"
$APT_GET remove ruby1.8*
$APT_GET install ruby1.9.1 ruby1.9.1-dev libruby1.9.1 
$APT_GET install build-essential
gem install --no-rdoc --no-ri chef
ln -sf gem1.9.1 /usr/bin/gem
ln -sf ruby1.9.1 /usr/bin/ruby
for dir in log backups run cache lib; do
  mkdir -p /var/$dir/chef
done
mkdir /etc/chef
ln -s /var/lib/gems/1.9.1/bin/chef-client /usr/bin/chef-client
cat - >/etc/chef/bootstrap.json <<EOF
{
  "run_list": [
    "role[$role]"
  ]
}
EOF
cat - >/etc/chef/client.rb <<EOF
log_level          :info
log_location       "/var/log/chef/client.log"
ssl_verify_mode    :verify_none
validation_client_name "chef-validator"
validation_key         "/etc/chef/validation.pem"
client_key               "/etc/chef/client.pem"
chef_server_url    "$chef_server"
file_cache_path    "/var/cache/chef"
file_backup_path  "/var/backups/chef"
pid_file           "/var/run/chef/client.pid"
Chef::Log::Formatter.show_time = true
EOF
cat - >/etc/chef/validation.pem <<EOF
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
EOF
/usr/bin/chef-client -j /etc/chef/bootstrap.json -s 20 -i 300 -d

Launch an instance with ec2-run-instances ami-fffffff --user-data-file chef-bootstrap.sh If you bootstrap a variety of different roles, you can use a script to fill in the blanks in the script then launch the image, personally I use a Rake script for that.

-- AvishaiIshShalom - 21 May 2011
Topic revision: r2 - 14 Aug 2011 - 11:00:52 - AvishaiIshShalom
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback