Last active
December 16, 2015 22:09
-
-
Save fabianmu/5505444 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
#!/usr/bin/env bash | |
# call like this on the target server: | |
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='[email protected]:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 ) | |
# You will need to ensure that the ssh key is already set up on the server. | |
set -e | |
export WWW_DIR="/var/www" | |
export CHEF_DIR="/var/www/html" | |
sudo rm -rf $CHEF_DIR | |
mkdir -p "$CHEF_DIR" | |
echo "-- Installing Packages" | |
yes | sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert git-core | |
echo "-- Installing RubyGems" | |
if [[ ! (`command -v gem`) ]]; then | |
cd /tmp | |
wget -c http://production.cf.rubygems.org/rubygems/rubygems-2.0.3.tgz | |
tar zxf rubygems-2.0.3.tgz | |
cd rubygems-2.0.3 | |
sudo ruby setup.rb --no-format-executable | |
fi | |
echo "-- Installing Chef gem" | |
#sudo gem install chef ohai --no-ri --no-rdoc | |
wget -O- https://opscode.com/chef/install.sh | sudo bash | |
#mkdir -p "$WWW_DIR/.chef" | |
#cat <<EOF > $WWW_DIR/.chef/knife.rb | |
#log_level :debug | |
#log_location STDOUT | |
#node_name '$NODENAME' | |
#cookbook_path [ '$CHEF_DIR/cookbooks' ] | |
#cookbook_copyright "Cheftest Inc." | |
#EOF | |
echo "-- Cloning repository" | |
cd $CHEF_DIR | |
#mkdir -p "$CHEF_DIR/config" | |
sudo chown -R www-data:www-data . | |
sudo -Hu www-data git clone $CHEFREPO . | |
sudo -Hu www-data git submodule update --init --recursive | |
echo "-- Setting up chef config" | |
#cat <<EOF > $CHEF_DIR/config/solo.rb | |
#log_level :debug | |
#data_bag_path "$CHEF_DIR/data_bags" | |
#file_cache_path "$CHEF_DIR" | |
#cookbook_path "$CHEF_DIR/cookbooks" | |
#role_path "$CHEF_DIR/roles" | |
#json_attribs "$CHEF_DIR/config/default.json" | |
#EOF | |
#cat <<EOF > $CHEF_DIR/config/default.json | |
#{ "chef_environment":"$CHEF_ENV","run_list": $RUNLIST } | |
#EOF | |
printf " | |
=== Run the following === | |
sudo chef-solo -c chef/config/solo.rb | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment