Skip to content

Instantly share code, notes, and snippets.

@hh
Created July 7, 2011 07:33
Show Gist options
  • Save hh/1069044 to your computer and use it in GitHub Desktop.
Save hh/1069044 to your computer and use it in GitHub Desktop.
Chef Server setup for Ubuntu 11.04/natty on Amazon ec2
#!/bin/bash
#ec2-run-instances --user-data-file chefserver-ec2-userdata.sh -g chef-server --key mykey -t m1.large --instance-initiated-shutdown-behavior terminate ami-1aad5273 | grep INSTANCE | INSTANCE=`cut -f 2` | xargs -I XXX ec2-create-tags XXX --tag Name=chefserver ; sleep 60 ; ec2-describe-instances $INSTANCE | grep INSTANCE | grep running | echo ssh ubuntu@`cut -f 4`
# ami-1aad5273 - ubuntu 11.04 64bit server ebs
# ami-2cc83145 - alestic ubunt 10.04 LTS 32bit server ebs
# ami-2ec83147 - alestic ubunt 10.04 LTS 64bit server ebs
# ami-8e1fece7 - amazon 64 bit ebs
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
set -e -x
# START CHEF BOOSTRAP
# Mainly a scripting of http://wiki.opscode.com/display/chef/Package+Installation+on+Debian+and+Ubuntu
REAL_HOSTNAME=chef.example.net
[email protected]
PUBLIC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
LOCAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
PUBLIC_HOSTNAME=$(curl -s http://instance-data.ec2.internal/latest/meta-data/public-hostname)
LOCAL_HOSTNAME=$(curl -s http://instance-data.ec2.internal/latest/meta-data/local-hostname)
# Add optscode repo, update, upgrade and get ruby-dev and build-essential
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/[email protected] | sudo apt-key add -
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install ruby-dev build-essential
# configure chef debconf parameters
cat<<DEBCONF | debconf-set-selections
chef-solr chef-solr/amqp_password password XYZXYZXYZ
chef-server-webui chef-server-webui/admin_password password XYZXYZXYZ
chef chef/chef_server_url string http://$REAL_HOSTNAME:4000
DEBCONF
# set hostname, and 'chef' shortname, setting IP based on local IP
echo $REAL_HOSTNAME | tee /etc/hostname
hostname $REAL_HOSTNAME
echo $LOCAL_IP $REAL_HOSTNAME chef | tee -a /etc/hosts
sudo apt-get -y install chef chef-server
# * Starting chef-server
# /usr/lib/ruby/1.8/rubygems/remote_fetcher.rb:14: uninitialized constant Gem::UserInteraction (NameError)
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/1.8/rubygems/spec_fetcher.rb:4
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef/provider/package/rubygems.rb:31
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef/providers.rb:59
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef.rb:25
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/sbin/chef-server:40
# ...fail!
# root@chef:~# /etc/init.d/chef-server-webui start
# * Starting chef-server-webui
# /usr/lib/ruby/1.8/rubygems/remote_fetcher.rb:14: uninitialized constant Gem::UserInteraction (NameError)
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/1.8/rubygems/spec_fetcher.rb:4
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef/provider/package/rubygems.rb:31
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef/providers.rb:59
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/lib/ruby/vendor_ruby/chef.rb:25
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
# from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
# from /usr/sbin/chef-server-webui:43
# ...fail!
# more fun with knife
#sudo apt-get install libnet-ssh-multi-ruby libhighline-ruby #libfog-ruby # fog seems missing
# START SETUP BASE SYSTEM
apt-get -y install ncurses-term # because I use emacs ansi-term and want /usr/share/terminfo/e/eterm-color
apt-get -y install screen # because it's awesome, but needs a decent default config...
echo export HISTSIZE=5000 | tee -a /etc/skel/.bash_profile | tee -a /root/.bash_profile
cat <<"EOS"| tee /etc/skel/.screenrc | tee /root/.screenrc
source /etc/screenrc
defscrollback 5000
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
defhstatus "screen ^A (^Aa) | $USER@^AH"
hardstatus off
caption always "%{Yk} %H%{k}|%{W}%-w%{+u}%n %t%{-u}%+w"
caption string "%{yk}%H %{Kk}%{g}%-w%{kR}%n %t%{Kk}%{g}%+w"
startup_message off
vbell off
EOS
# END SETUP BASE SYSTEM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment