Skip to content

Instantly share code, notes, and snippets.

@pmorton
Forked from hmalphettes/ubuntu-12.04-gems.erb
Created May 24, 2012 16:35
Show Gist options
  • Save pmorton/2782612 to your computer and use it in GitHub Desktop.
Save pmorton/2782612 to your computer and use it in GitHub Desktop.
Chef bootstrap with RVM on Ubuntu 12.04
bash -c '
UBUNTU_MIRROR=us-west-1.ec2.archive.ubuntu.com.s3.amazonaws.com
RUBY_VERSION=1.9.3-p194
echo "Updating the Ubuntu Mirror Source"
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.archive\.ubuntu\.com/http:\/\/$UBUNTU_MIRROR/g" /etc/apt/sources.list
if [ ! -f /usr/local/rvm/bin/${RUBY_VERSION}_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
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
source /etc/profile
which rvm
if [ "$?" != "0" ]; then
echo "Failed to install rvm"
exit 5
fi
rvm install $RUBY_VERSION <%= "--proxy #{knife_config[:bootstrap_proxy]}" if knife_config[:bootstrap_proxy] %> -C --sysconfdir=/etc
if [ "$?" != "0" ]; then
echo "Failed to install $RUBY_VERSION"
exit 6
fi
rvm use $RUBY_VERSION --default
fi
echo -e "Disabling ri & rdoc for gem installations."
echo "gem: --no-rdoc --no-ri" >> /etc/gemrc
chmod 0644 /etc/gemrc
source /etc/profile
gem update --system
gem update
gem install chef --verbose <%= bootstrap_version_string %>
if [ -f /usr/bin/chef-client ]; then
rm -f /usr/bin/chef-client
fi
rvm wrapper $RUBY_VERSION $RUBY_VERSION chef-client
ln -nfs /usr/local/rvm/bin/$RUBY_VERSION_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
chmod 0640 /etc/chef/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
chmod 0640 /etc/chef/encrypted_data_bag_secret
<% end -%>
(
cat <<'EOP'
<%= config_content %>
EOP
) > /etc/chef/client.rb
chmod 0644 /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