Skip to content

Instantly share code, notes, and snippets.

@mlavin
Created January 11, 2012 16:44
Show Gist options
  • Save mlavin/1595546 to your computer and use it in GitHub Desktop.
Save mlavin/1595546 to your computer and use it in GitHub Desktop.
Fabric Package Install
import ConfigParser
import os
from fabric.api import env, sudo
from fabric.contrib import files
SERVER_ROLES = ['dbmaster', 'app', 'lb', ]
env.roledefs = dict.fromkeys(SERVER_ROLES, [])
# Directory structure
PROJECT_ROOT = os.path.dirname(__file__)
CONF_ROOT = os.path.join(PROJECT_ROOT, 'conf')
def install_packages(*roles):
"""
Install packages for the given roles.
"""
roles = list(roles)
if roles == ['all', ]:
roles = SERVER_ROLES
if 'base' not in roles:
roles.insert(0, 'base')
config_file = os.path.join(CONF_ROOT, u'packages.conf' % env)
config = ConfigParser.SafeConfigParser()
config.read(config_file)
for role in roles:
if config.has_section(role):
# Get ppas
if config.has_option(role, 'ppas'):
for ppa in config.get(role, 'ppas').split(' '):
sudo(u'add-apt-repository %s' % ppa)
# Get sources
if config.has_option(role, 'sources'):
for section in config.get(role, 'sources').split(' '):
source = config.get(section, 'source')
key = config.get(section, 'key')
files.append(u'/etc/apt/sources.list', source, use_sudo=True)
sudo(u"wget -q %s -O - | sudo apt-key add -" % key)
sudo(u"apt-get update")
sudo(u"apt-get install -y %s" % config.get(role, 'packages'))
sudo(u"apt-get upgrade -y")
[base]
packages = python-software-properties dpkg-dev wget build-essential git-core subversion mercurial libnet-cidr-perl munin-node vim ntp
[app]
packages = python2.6 python-all-dev python-setuptools libmysqlclient15-dev libevent-1.4-2 libevent-core-1.4-2 libevent-extra-1.4-2 libevent-dev rabbitmq-server memcached libjpeg62 libjpeg62-dev zlib1g-dev supervisor redis-server
ppas = ppa:rwky/redis
sources = rabbitmq-source
[lb]
packages = nginx
ppas = ppa:nginx/stable
[dbmaster]
packages = mysql-server mysql-common mysql-client
[rabbitmq-source]
source = deb http://www.rabbitmq.com/debian/ testing main
key = http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment