Skip to content

Instantly share code, notes, and snippets.

@darrinholst
Created January 6, 2012 16:02
Show Gist options
  • Save darrinholst/1571189 to your computer and use it in GitHub Desktop.
Save darrinholst/1571189 to your computer and use it in GitHub Desktop.
chef bootstraper for amazon-linux
bash -c '
#
# make sure sudo users have the full path...
#
# sudo visudo
# Defaults env_keep += "PATH"
# Defaults !secure_path
#
# run this command from this repository to bootstrap a node
#
# knife bootstrap ADDRESS --sudo -x ec2-user -i ~/.ssh/ec2.pem -N NODE_NAME -d amazon-linux
# --------------------------------------------------------
# development tools
# --------------------------------------------------------
hash gcc &> /dev/null
if [ $? -eq 1 ]; then
sudo yum -y install openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel
fi
# --------------------------------------------------------
# git
# --------------------------------------------------------
hash git &> /dev/null
if [ $? -eq 1 ]; then
yum -y install git
fi
# --------------------------------------------------------
# make sure /usr/local/bin is on the path
# --------------------------------------------------------
if [ ! -f /etc/profile.d/usrlocal.sh ]; then
echo "export PATH=\"/usr/local/bin:\$PATH\"" >> /etc/profile.d/usrlocal.sh
chmod +x /etc/profile.d/usrlocal.sh
source /etc/profile.d/usrlocal.sh
fi
# --------------------------------------------------------
# ruby 1.9.2
# --------------------------------------------------------
if [[ `ruby --version` != ruby\ 1.9.2* ]]; then
pushd /tmp
rm -rf ruby-build
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
./install.sh
popd
ruby-build 1.9.2-p290 /usr/local
gem install bundler --no-rdoc --no-ri
fi
# --------------------------------------------------------
# chef-client
# --------------------------------------------------------
gem install ohai --no-rdoc --no-ri
gem install chef --no-rdoc --no-ri <%= bootstrap_version_string %>
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
chef-client -j /etc/chef/first-boot.json -E "<%= bootstrap_environment %>"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment