Create a gist now

Instantly share code, notes, and snippets.

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
cat > /tmp/chef.json <<-JSON
{ "instance_role": "my_app",
"run_list": ["role[my_app]"]
echo Creating working directory ...
run sudo rm -rf /etc/chef \; sudo mkdir -p /etc/chef \; sudo chown deploy:deploy /etc/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

A really useful one. Thanks!

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