Skip to content

Instantly share code, notes, and snippets.

@douglasjarquin
Forked from darrinholst/amazon-linux.erb
Last active February 29, 2016 01:42
Show Gist options
  • Save douglasjarquin/2771598 to your computer and use it in GitHub Desktop.
Save douglasjarquin/2771598 to your computer and use it in GitHub Desktop.
Chef bootstrap template 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
yum groupinstall -y "Development tools"
yum install -y libxml2-devel libxslt-devel
fi
# --------------------------------------------------------
# git
# --------------------------------------------------------
hash git &> /dev/null
if [ $? -eq 1 ]; then
yum install -y 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.3
# --------------------------------------------------------
if [[ `ruby --version` != ruby\ 1.9.3* ]]; then
yum install -y ruby19 ruby19-devel rubygems19 rubygem19-rdoc rubygem19-rake rubygem19-bigdecimal
ln -sf /usr/bin/ruby1.9 /usr/bin/ruby
ln -sf /usr/bin/gem1.9 /usr/bin/gem
ln -sf /usr/bin/irb1.9 /usr/bin/irb
ln -sf /usr/bin/rdoc1.9 /usr/bin/rdoc
ln -sf /usr/bin/rake1.9 /usr/bin/rake
fi
gem update --system --no-document
gem install bundler bigdecimal rdoc rake multi_json aws-sdk fog --no-document
# --------------------------------------------------------
# chef-client
# --------------------------------------------------------
gem install ohai --no-document
gem install chef --no-document <%= 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