Skip to content

Instantly share code, notes, and snippets.

@hmalphettes
Created March 14, 2012 04:27
Show Gist options
  • Save hmalphettes/2034085 to your computer and use it in GitHub Desktop.
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
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 local VM: knife bootstrap 192.168.122.165 -x ubuntu -P ubuntu -d ubuntu-12.04-gems --sudo"
echo "Example local 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 --sudo"
echo " https://gist.github.com/1301693"
UBUNTU_MIRROR=sg
if [ '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:\/\/us\./http:\/\/$UBUNTU_MIRROR./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
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
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.*$/if [ "root" = "${USER}" -a -n "\${BASH_VERSION:-}" -o -n "\${ZSH_VERSION:-}" ] ; then/'"'"' /etc/profile.d/rvm.sh
source /etc/profile
which rvm
if [ "$?" != "0" ]; then
echo "Failed to install rvm"
exit 5
fi
rvm install 1.9.3-p125 <%= "--proxy #{knife_config[:bootstrap_proxy]}" if knife_config[:bootstrap_proxy] %>
if [ "$?" != "0" ]; then
echo "Failed to install ruby-1.9.3-p125"
exit 6
fi
rvm use 1.9.3-p125 --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