-
-
Save paulschwarz/2974764 to your computer and use it in GitHub Desktop.
Bootstrap Chef Solo on Ubuntu
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: | |
# CHEFREPO='git://github.com/paulsschwarz/vagrant-cookbooks.git' CHEF_ENV='production' bash <( curl -L https://raw.github.com/gist/2974764 ) | |
set -e | |
export RUBYGEMS_VERSION="1.8.24" | |
export CHEF_DIR="${HOME}/chef" | |
sudo rm -rf $CHEF_DIR | |
mkdir -p "$CHEF_DIR" | |
echo "-- Update apt-get" | |
apt-get update | |
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-$RUBYGEMS_VERSION.tgz | |
tar zxf rubygems-$RUBYGEMS_VERSION.tgz | |
cd rubygems-$RUBYGEMS_VERSION | |
sudo ruby setup.rb --no-format-executable | |
fi | |
echo "-- Installing Chef gem" | |
if [[ ! (`command -v ohai` && `command -v chef-solo`) ]]; then | |
sudo gem install chef ohai --no-ri --no-rdoc | |
fi | |
mkdir -p "$HOME/.chef" | |
cat <<EOF > $HOME/.chef/knife.rb | |
log_level :info | |
log_location STDOUT | |
node_name '$NODENAME' | |
cookbook_path [ '$CHEF_DIR/cookbooks', '$CHEF_DIR/site-cookbooks' ] | |
cookbook_copyright "Cheftest Inc." | |
EOF | |
echo "-- Cloning repository" | |
cd $CHEF_DIR | |
git clone $CHEFREPO cookbooks | |
cd cookbooks | |
git submodule update --init --recursive | |
mkdir $CHEF_DIR/config | |
echo "-- Setting up chef config" | |
cat <<EOF > $CHEF_DIR/config/solo.rb | |
log_level :info | |
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": | |
[ | |
"recipe[apt]", | |
"recipe[apache2]", | |
"recipe[php]", | |
"recipe[mysql::server]" | |
] | |
} | |
EOF | |
printf " | |
=== Run the following === | |
sudo chef-solo -c $CHEF_DIR/config/solo.rb | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the above was done under root then the run command will be:
$ sudo chef-solo -c /root/chef/config/solo.rb