Example #1
def hosts():
  current_role = _current_role()
  hostsfile = util.files('farmboy/hosts')
  hosts = []
  hosts.append(' localhost farmboy-%s' % current_role)
  # TODO(termie): does this break if we use callable roledefs?
  for role, role_hosts in env.roledefs.iteritems():
    if len(role_hosts) == 1:
      if role == current_role:

      hosts.append('%s farmboy-%s' % (util.host(role_hosts[0]), role))

    for i, role_host in enumerate(role_hosts):
      hosts.append('%s farmboy-%s-%s' % (util.host(role_host), role, i))

  hosts_str = '\n'.join(hosts)

      template_source = hostsfile,
      context  = {'hosts': hosts_str},
      path     = '/etc/hosts',
      owner    = 'root',
      group    = 'root',
      mode     = '644',
      use_sudo = True)
Example #2
def demo():
    """Example deployment of an haproxy+nginx+gunicorn+django."""
    if env.roledefs['apt']:
    execute(django.deploy, path=env.farmboy_django_app)

    print ('Alright! Check out your site at: http://%%s'
            %% util.host(env.roledefs['proxy'][0]))
Example #3
env.key_filename = %(keyfile)s

# Define which servers go with which roles.
# POWER TIP: These can defined as callables as well if you want to load
#            the servers in some more dynamic way.
# POWER TIP: You might also want to separate these out into a yaml file
#            and do `env.roledefs = yaml.load(open('farmboy.yaml'))`
#            or use the helper `env.roledefs = util.load_roledefs()`

# Since we're be using apt caching, point out where that proxy will live.
# POWER TIP: If you're already using such a proxy, you can just point this
#            at that server and skip the `execute(aptcacher.deploy)` step.
if env.roledefs['apt']:
    apt = env.roledefs['apt'][0]
    env.farmboy_apt_proxy = 'http://%%s:3142' %% util.host(apt)

# Where our django app lives (this directory will be pushed to web servers).
# This is expected to be the directory that contains the manage.py file for
# a default django setup.
# POWER TIP: We expect this to be in the current directory by default
#            but a full path works here, too.
# POWER TIP: You can set the path directly as we do below in the execute
#            call, but if none is set it will default to using the this
#            env variable.
env.farmboy_django_app = 'demo'

# Where to find the template files to use when configuring services.
# POWER TIP: We'll fall back to the defaults shipped with farmboy for
#            any files not found in this location.
# POWER TIP: TODO(termie) Use `farmboy files $some_module` to get the