Created
March 14, 2012 04:27
-
-
Save hmalphettes/2034085 to your computer and use it in GitHub Desktop.
Chef bootstrap With root-only rvm and ruby 1.9.2 on ubuntu 12.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash -c ' | |
echo "boostrap chef on a ubuntu VM. Install ruby via rvm sandbox it for the root user: does not install rvm system wide." | |
echo "Example VM already booted: knife bootstrap 192.168.122.165 -x ubuntu -P ubuntu -d ubuntu-12.04-gems --node-name my_node --run-list role[intalio_micro_all] --environment intalio-CF --sudo" | |
echo "Example EC2 with knife-ec2: knife bootstrap ec2-122-248-197-139.ap-southeast-1.compute.amazonaws.com -i ~/.ec2/hmalphettes-ap.pem -x ubuntu -d ubuntu-12.04-gems i --run-list \"role[intalio_micro_all]\" --environment intalio-CF --no-host-key-verify --sudo" | |
echo "Example EC2 with knife-ec2: knife ec2 server create -I $UBUNTU_AMI -f m1.large -x ubuntu -d ubuntu-12.04-gems -i $EC2_KEYPAIR_PEM \"--run-list role[intalio_micro_all]\" -G http-https-ssh-smtp-vmreg -N ec2-ubuntu-new --region $EC2_REGION --availability-zone ap-southeast-1b --ebs-size $SIZE --no-host-key-verify --environment intalio-CF" | |
echo "Example HP Cloud with knife-hp: knife hp server create --flavor 103 --image 5579 --ssh-key intaliohp --groups ssh-http-https-vm-reg -x ubuntu -i ~/.ssh/intaliohp.pem -d ubuntu-12.04-gems --run-list role[intalio_micro_all]\" --environment intalio-CF" | |
echo "Example vsphere with knife-vsphere: knife vsphere vm clone NewNode --template Template-Ubuntu-Unclouded --start on --datastore 4c41b761-464a84fe-7f4c-0025b31edf26 --ccpu 2 --cram 6 -x ubuntu -P ubuntu -d ubuntu-12.04-gems --node-name hugues_esx_node --run-list role[intalio_micro_all] --environment intalio-CF --no-host-key-verify" | |
echo " https://gist.github.com/1301693" | |
echo "Use the 5 quotes to escape the single quotes within the command" | |
UBUNTU_MIRROR=sg | |
if [ -n "$UBUNTU_MIRROR" -a "us" != "$UBUNTU_MIRROR" ]; then | |
touch /etc/apt/sources.list | |
if [ "$?" != "0" ]; then | |
echo "Failed to touch /etc/apt/sources.list. are you root?" | |
exit 1 | |
fi | |
sed -i -e "s/http:\/\/archive\.ubuntu\.com/http:\/\/$UBUNTU_MIRROR.archive.ubuntu.com/g" /etc/apt/sources.list | |
fi | |
<% if knife_config[:bootstrap_proxy] -%> | |
( | |
cat <<'EOP' | |
<%= "proxy = #{knife_config[:bootstrap_proxy]}" %> | |
EOP | |
) > ~/.curlrc | |
<% end -%> | |
if [ ! -f /usr/bin/chef-client ]; then | |
curr_lang=`locale | grep LANG= | cut -d'=' -f2` | |
if [ -z "$curr_lang" ]; then | |
locale-gen | |
locale-gen en_US.UTF-8 | |
update-locale LANG=en_US.UTF-8 | |
curr_lang=`locale | grep LANG= | cut -d"=" -f2` | |
if [ -z "$curr_lang" ] ;then | |
echo "Unable to specify a locale with a specific LANG" | |
exit 2 | |
fi | |
fi | |
apt-get update | |
if [ "$?" != "0" ]; then | |
echo "Failed to run apt-get update. are you root?" | |
exit 1 | |
fi | |
apt-get install -y build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config | |
echo "Using a root only install as documented on http://beginrescueend.com/support/faq/" | |
echo "export rvm_prefix=/root" > /root/.rvmrc | |
echo "export rvm_path=/root/.rvm" >> /root/.rvmrc | |
source /root/.rvmrc | |
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) | |
sed -i '"'"'s/^.*BASH_VERSION.*ZSH_VERSION.*$/[ "root" = "${USER}" -a -n "\${BASH_VERSION:-}" -o -n "\${ZSH_VERSION:-}" ] \&\&/'"'"' /etc/profile.d/rvm.sh | |
source /etc/profile | |
which rvm | |
if [ "$?" != "0" ]; then | |
echo "Failed to install rvm" | |
exit 5 | |
fi | |
rvm reinstall 1.9.3 <%= "--proxy #{knife_config[:bootstrap_proxy]}" if knife_config[:bootstrap_proxy] %> | |
if [ "$?" != "0" ]; then | |
echo "Failed to install ruby-1.9.3" | |
exit 6 | |
fi | |
rvm use 1.9.3 --default | |
fi | |
source /etc/profile | |
set +e | |
gem update --system --no-rdoc --no-ri | |
if [ $? != 0 ]; then | |
echo "Retry 1" | |
gem update --system --no-rdoc --no-ri | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 2" | |
gem update --system --no-rdoc --no-ri | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 3" | |
gem update --system --no-rdoc --no-ri | |
fi | |
gem update --no-rdoc --no-ri | |
if [ $? != 0 ]; then | |
echo "Retry 1" | |
gem update --no-rdoc --no-ri | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 2" | |
gem update --no-rdoc --no-ri | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 3" | |
gem update --no-rdoc --no-ri | |
fi | |
if [ $? != 0 ]; then | |
echo "failed to gem update" | |
exit 1 | |
fi | |
gem install ohai --no-rdoc --no-ri --verbose | |
if [ $? != 0 ]; then | |
echo "Retry 1" | |
gem install ohai --no-rdoc --no-ri --verbose | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 2" | |
gem install ohai --no-rdoc --no-ri --verbose | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 3" | |
gem install ohai --no-rdoc --no-ri --verbose | |
fi | |
if [ $? != 0 ]; then | |
echo "failed to install ohai" | |
exit 1 | |
fi | |
gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> | |
if [ $? != 0 ]; then | |
echo "Retry 1" | |
gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 2" | |
gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> | |
fi | |
if [ $? != 0 ]; then | |
echo "Retry 3" | |
gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> | |
fi | |
if [ $? != 0 ]; then | |
echo "failed to install chef" | |
exit 1 | |
fi | |
if [ -f /usr/bin/chef-client ]; then | |
rm -f /usr/bin/chef-client | |
fi | |
which_chef_client=$(which chef-client) | |
if [ -z "$which_chef_client" ]; then | |
echo "chef-client cant be found on the path: installation failed" | |
exit 1 | |
fi | |
ln -nfs $(which chef-client) /usr/bin/chef-client | |
mkdir -p /etc/chef | |
( | |
cat <<'EOP' | |
<%= validation_key %> | |
EOP | |
) > /tmp/validation.pem | |
awk NF /tmp/validation.pem > /etc/chef/validation.pem | |
rm /tmp/validation.pem | |
<% if @chef_config[:encrypted_data_bag_secret] -%> | |
( | |
cat <<'EOP' | |
<%= encrypted_data_bag_secret %> | |
EOP | |
) > /tmp/encrypted_data_bag_secret | |
awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret | |
rm /tmp/encrypted_data_bag_secret | |
<% end -%> | |
( | |
cat <<'EOP' | |
<%= config_content %> | |
EOP | |
) > /etc/chef/client.rb | |
( | |
cat <<'EOP' | |
<%= { "run_list" => @run_list }.to_json %> | |
EOP | |
) > /etc/chef/first-boot.json | |
<%= start_chef %>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment