Skip to content

Instantly share code, notes, and snippets.

@assaf
Created February 16, 2012 00:02
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assaf/1840224 to your computer and use it in GitHub Desktop.
Save assaf/1840224 to your computer and use it in GitHub Desktop.
Deploy using chef-solo
# Run command(s) over SSH
run() {
ssh deploy@${HOST} -t $* || exit 1
}
# Transfer all the specified files/directories to working directory
upload() {
tar czf - $* | ssh deploy@${HOST} tar xzf - -C /etc/chef || exit 1
}
# solo.rb tells chef-solo where to find cookbooks, roles and data bags and.
cat > /tmp/solo.rb <<-RB
file_cache_path "/tmp/chef"
cookbook_path "/etc/chef/cookbooks"
role_path "/etc/chef/roles"
data_bag_path "/etc/chef/data_bags"
log_level :info
RB
cat > /tmp/chef.json <<-JSON
{ "instance_role": "my_app",
"run_list": ["role[my_app]"]
}
JSON
echo Creating working directory ...
run sudo rm -rf /etc/chef \;\
sudo mkdir -p /etc/chef \;\
sudo chown deploy:deploy /etc/chef \;\
sudo rm -rf /tmp/chef \;\
mkdir -p /tmp/chef
echo Uploading cookbooks and related files ...
cd /tmp ; upload chef.json solo.rb
cd - ; upload cookbooks data_bags roles
echo Running Chef solo ...
run sudo /usr/bin/chef-solo -c /etc/chef/solo.rb -j /etc/chef/chef.json
growlnotify -t Chef -m "Deployed to ${HOST}"
Copy link

ghost commented Jun 5, 2012

A really useful one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment