Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zzondlo/2329488 to your computer and use it in GitHub Desktop.
Save zzondlo/2329488 to your computer and use it in GitHub Desktop.
Chef bootstrap template for Ubuntu 10.04 LTS
### Ensure variables are declared
[[ -z "$RUBY_VERSION" ]] && printf ">>> RUBY_VERSION must be set.\n" && exit 10
[[ -z "$RUBY_HOME" ]] && printf ">>> RUBY_HOME must be set.\n" && exit 11
### Install Packages
set -x
apt-get update
apt-get install -y sed grep tar gzip bzip2 bash curl git-core \
build-essential bison openssl libreadline6 libreadline6-dev \
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 \
libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf \
libc6-dev ssl-cert
if [[ ! -d "$RUBY_HOME" ]] ; then
### Install Self Contained Ruby with ruby-build
clone_dir=/tmp/ruby-build-$$
git clone https://github.com/sstephenson/ruby-build.git $clone_dir
$clone_dir/bin/ruby-build "$RUBY_VERSION" "$RUBY_HOME"
rm -rf $clone_dir
unset clone_dir
fi
### Installing Chef Gems
# core chef gems
${RUBY_HOME}/bin/gem install ohai --no-ri --no-rdoc
${RUBY_HOME}/bin/gem install chef --no-ri --no-rdoc <%= bootstrap_version_string %>
# used by user resource to set passwords
${RUBY_HOME}/bin/gem install ruby-shadow --no-ri --no-rdoc
# symlink chef binaries into /usr/bin
for b in chef-client chef-solo knife shef ohai ; do
ln -snf "${RUBY_HOME}/bin/$b" "/usr/bin/$b"
done
### Chef Cache Directory Setup
mkdir -p /var/chef/cache
chown root:root /var/chef/cache
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
# version of Ruby to install
RUBY_VERSION="1.9.3-p125"
# install base directory for Ruby installs
RUBY_HOME="/opt/chef_ruby"
<%=
# load in the common bootstrapping code
require 'erb'
common = File.join(File.dirname(__FILE__),
%w{.chef bootstrap _ubuntu-10.04-standalone.sh})
ERB.new(IO.read(File.expand_path(common))).result(binding)
-%>'
apt-get install -y rsync
<% unless ENV['SOLO_BOOTSTRAP'] -%>
(
cat <<'EOP'
<%= validation_key %>
EOP
) > /tmp/validation.pem
awk NF /tmp/validation.pem > /etc/chef/validation.pem
rm /tmp/validation.pem
(
cat <<'EOP'
<%= config_content %>
EOP
) > /etc/chef/client.rb
(
cat <<'EOP'
<%= { "run_list" => @run_list }.to_json %>
EOP
) > /etc/chef/first-boot.json
${RUBY_HOME}/bin/chef-client \
-j /etc/chef/first-boot.json \
-E <%= bootstrap_environment %>
<% end -%>
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment