Skip to content

Instantly share code, notes, and snippets.

@capotej
Created February 27, 2013 19:08
Show Gist options
  • Save capotej/5050681 to your computer and use it in GitHub Desktop.
Save capotej/5050681 to your computer and use it in GitHub Desktop.
chef-solo deployer/bootstrapper
from fabric.api import *
from fabric.contrib.files import exists
from fabric.contrib.project import upload_project
## Usage
# Full run, bootstraps if needed
# fab chef:name_of_runlist,hosts=1.1.1.1 --password=1234 --user=foo
# fab chef:name_of_runlist,hosts=1.1.1.1 -i=path/to/pem --user=foo
# Bootstrap only
# fab bootstrap:hosts=1.1.1.1 --password=1234 --user=foo
def bootstrap():
base_packages = [
"libshadow-ruby1.8",
"debhelper",
"curl",
"git-core",
"bzip2",
"zlib1g-dev",
"libssl-dev",
"libopenssl-ruby",
"libreadline-dev",
"ruby",
"ruby-dev",
"build-essential",
"rubygems"
]
run('sudo apt-get update')
run('sudo apt-get upgrade -y')
run('sudo apt-get install -y %s' % ' '.join(base_packages))
run('sudo gem install --no-rdoc --no-ri chef ohai')
def chef(runlist):
chef_binary = "/var/lib/gems/1.8/bin/chef-solo"
if not exists(chef_binary):
bootstrap()
if not exists('/tmp/chef'):
run('mkdir /tmp/chef')
run('rm -rf /tmp/chef/*')
upload_project(remote_dir="/tmp/chef")
run('cd /tmp/chef/cookbooks && sudo /var/lib/gems/1.8/bin/chef-solo -c solo.rb -j %s.json' % runlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment