-
-
Save zzondlo/2314892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NODENAME="%farm_name%-%friendly_name%-%instance_id%" | |
LOG=/var/log/chef-bootstrap.log | |
DIRECTORY=/etc/chef | |
CLIENT_RB=$DIRECTORY/client.rb | |
CHEF_JSON=$DIRECTORY/chef.default.json | |
PRIVATE_KEY=$HOME/.ssh/id_rsa | |
PUBLIC_KEY=$PRIVATE_KEY.pub | |
function say_start { | |
echo -e "*** $1" >> $LOG | |
} | |
function say_done { | |
echo -e "*** Done!\n" >> $LOG | |
} | |
say_start "Starting Bootstrap Script version 26" | |
export $NODENAME | |
# Install needed packages | |
say_start "Installing needed packages..." | |
apt-get install zsh build-essential git-core zlib1g-dev -y -qq >> $LOG | |
say_done | |
# Setup .gemrc to not install gem docs | |
say_start "Setting up .gemrc to not install gem docs..." | |
echo "gem: --no-ri --no-rdoc" > $HOME/.gemrc | |
say_done | |
# Install the private key for github access | |
say_start "Installing the private key for github access..." | |
echo "-----BEGIN RSA PRIVATE KEY----- | |
LOL KEYS | |
-----END RSA PRIVATE KEY-----" > $PRIVATE_KEY | |
say_done | |
# Set the proper file permissions for id_rsa | |
say_start "Setting the proper file permissions for .ssh/*..." | |
chmod 0700 $HOME/.ssh | |
chmod 0600 $PRIVATE_KEY | |
say_done | |
# Setup SSH configuration | |
say_start "Setting up SSH configuration..." | |
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> $HOME/.ssh/config | |
say_done | |
# Clone the git repo (chef credentials, etc...) | |
say_start "Cloning the git repo (chef credentials, etc.)..." | |
rm -rf /tmp/devops | |
git clone --quiet [email protected]:vitrue/devops.git /tmp/devops | |
say_done | |
testme=%Which_ruby_(x.x.x)% | |
say_start "This is the testme value ${testme}" | |
say_done | |
if [ $testme == "1.8.7"] | |
then | |
GEM='/usr/bin/gem' | |
ruby="1.8.7" | |
elif [ -z $testme ] | |
then | |
GEM='/usr/local/bin/gem' | |
dl="https://s3.amazonaws.com/vitruePackages/ruby/ruby-1.9.2.deb" | |
ruby="1.9.2" | |
else | |
GEM='/usr/local/bin/gem' | |
dl="https://s3.amazonaws.com/vitruePackages/ruby/ruby-${testme}.deb" | |
ruby=$testme | |
fi | |
say_start "This is the ruby value ${ruby}" | |
say_done | |
if [ $ruby == "1.8.7"] | |
then | |
say _start "Installing Ruby 1.8.7" | |
sudo apt-get install ruby rubygems libopenssl-ruby ruby1.8-dev -y -qq | |
say_start "Updating RubyGems..." | |
$GEM install rubygems-update >> $LOG | |
/var/lib/gems/1.8/bin/update_rubygems >> $LOG | |
say_done | |
else | |
say_start "Downloading Ruby ${ruby}" | |
cd /tmp && wget $dl | |
say_done | |
say_start "Installing Ruby ${ruby}" | |
dpkg -i /tmp/ruby-${ruby}.deb | |
say_done | |
say_start "Installing ruby devs" | |
sudo apt-get install ruby1.9-dev -y -qq | |
say_done | |
say_start "Updating gem source" | |
$GEM update --system | |
say_done | |
say_start "Setting up .gemrc to not install gem docs..." | |
echo "gem: --no-ri --no-rdoc" > $HOME/.gemrc | |
say_done | |
fi | |
# Install the chef gem | |
say_start "Installing the chef gem..." | |
$GEM install chef >> $LOG | |
say_done | |
# Install the cloudkick gem | |
say_start "Installing cloudkick gem..." | |
$GEM install cloudkick >> $LOG | |
say_done | |
# Copy the chef client configuration for chef-client calls | |
say_start "Configuring the chef client..." | |
if [ ! -d $DIRECTORY ] | |
then mkdir $DIRECTORY | |
else rm -f $DIRECTORY/* | |
fi | |
cp /tmp/devops/chef-repo/client-config/client.rb $DIRECTORY | |
cp /tmp/devops/chef-repo/client-config/validation.pem $DIRECTORY | |
cp /tmp/devops/chef-repo/client-config/cloudkick_handler.rb $DIRECTORY | |
say_done | |
# Copy the chef encrypted data bag key to /vitrue/etc/ | |
say_start "retrieving the encrypted data bag key file" | |
if [ ! -d "/vitrue/etc" ] | |
then mkdir -p /vitrue/etc | |
fi | |
cp /tmp/devops/tools/etc/data_bag_key /vitrue/etc/data_bag_key | |
say_done | |
#seems better to explicitly set hostname rather than rely on the hostname as it's necessary to reset for some roles. | |
say_start "Adding the node name $NODENAME to client.rb" | |
if grep -v "node_name" /etc/chef/client.rb; then | |
echo "node_name \"$NODENAME\"" >> $CLIENT_RB | |
fi | |
say_done | |
say_start "Setting the Chef Environment for this instance..." | |
if test -n '%environment%' | |
then | |
echo 'environment "%environment%"' >> $CLIENT_RB | |
fi | |
say_done | |
# Set the run list for this instance | |
say_start "Setting the Chef run list for this instance..." | |
if test -n '%node_attributes%' | |
then | |
echo '{ %node_attributes%, "run_list": [ %chef_run_list% ]}' > $CHEF_JSON | |
else | |
echo '{"run_list": [ %chef_run_list% ]}' > $CHEF_JSON | |
fi | |
say_done | |
# Set the node name to be something intelligible | |
say_start "Setting the instance hostname to: $NODENAME" | |
if grep -v $NODENAME /etc/hosts; then | |
/bin/hostname $NODENAME >> $LOG | |
sed -i "s/^127.0.0.1/127.0.0.1 $NODENAME localhost/g" /etc/hosts | |
echo $NODENAME > /etc/hostname | |
fi | |
say_done | |
# Start the chef-client and connect to OpsCode | |
say_start "Starting the chef-client and connecting to OpsCode..." | |
chef-client >> $LOG | |
say_start "Node Name added to OpsCode. Running Chef for this instance" | |
chef-client --json-attributes $CHEF_JSON >> $LOG | |
say_done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment