Skip to content

Instantly share code, notes, and snippets.

@palewire
Created January 17, 2012 03:30
Show Gist options
  • Save palewire/1624433 to your computer and use it in GitHub Desktop.
Save palewire/1624433 to your computer and use it in GitHub Desktop.
fab bootstrap
from fabric.api import *
from openstack.compute import Compute
def bootstrap():
install_chef()
update_chef()
def install_chef():
"""
Install Chef on your server
"""
sudo('apt-get update', pty=True)
sudo('apt-get install -y git-core rubygems ruby ruby-dev', pty=True)
sudo('gem install chef', pty=True)
def update_chef():
"""
Update your server's software using Chef.
"""
local('rsync -av ./chef/ %s@%s:/etc/chef' % (env.user, env.hosts[0]))
sudo('cd /etc/chef && %s' % env.chef, pty=True)
def create_server(image='Ubuntu 11.04 (Natty)', flavor=256):
"""
Create a new server on Rackspace using the OpenStack API
"""
compute = Compute(
username=USER_NAME,
apikey=API_KEY
)
fl = compute.flavors.find(ram=flavor)
im = compute.images.find(name=image)
compute.servers.create(SERVER_NAME, image=im, flavor=fl)
@palewire
Copy link
Author

Obviously, this does not include private credentials I use on my system. After I create server I then configure a new fabric function with its login credentials. Then run fab <serverfunction> bootstrap.

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