Skip to content

Instantly share code, notes, and snippets.

@srinivasmohan
Created October 10, 2013 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srinivasmohan/6910728 to your computer and use it in GitHub Desktop.
Save srinivasmohan/6910728 to your computer and use it in GitHub Desktop.
Prebuild chef ready AMI
#!/bin/bash
#Run this on AMI ami-7e2da54e in us-west-2 (Supply this script as userdata) and build an AMI from the resulting instance.
#VPC Bootstrap User-data script generated at 2013-10-09 16:56:44 -0700
function logmsg {
echo "CHEF-VPC-INIT: $1"
}
CHEF_VERSION=11.6.0
RUBY_GEM_VER=1.8.25
test $UID == 0 || (echo "CHEF-VPC-INIT Error: must run as root!"; exit 1)
exec > >(tee /var/log/user-data-ami.log|logger -t user-data -s 2>/dev/null)
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
#Yes, really...
export REALLY_GEM_UPDATE_SYSTEM=1
apt-get -y update
apt-get -y install xfsprogs build-essential ruby1.9.1 ruby1.9.1-dev rubygems1.9.1 irb1.9.1 ri1.9.1 rdoc1.9.1 libopenssl-ruby1.9.1 libssl-dev zlib1g-dev finger links curl unzip traceroute libxslt-dev libxml2-dev
logmsg "Upgrading rubygems to $RUBY_GEM_VER and installing Chef gem version $CHEF_VERSION and misc gems"
#gem update --system
gem install rubygems-update -v $RUBY_GEM_VER && update_rubygems
gem install --no-rdoc --no-ri --version $CHEF_VERSION chef
gem install --no-rdoc --no-ri getopt mixlib-shellout bunny json sinatra curl hipchat-api thor nori fog
for x in /etc/chef /etc/chef/ /etc/chef/ohai /etc/chef/ohai/hints /var/log/chef /var/run/chef /var/chef /var/chef/backup /var/chef/cache /var/chef/handlers /var/chef/cookbooks
do
mkdir -p -v $x
done
#Supply ohai a hint file so it knows we are on EC2!
HINT=/etc/chef/ohai/hints/ec2.json
[ -f $HINT ] || touch $HINT && logmsg "Created Ohai ec2 hint file for VPC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment