Exemple #1
0
def hosts():
  current_role = _current_role()
  hostsfile = util.files('farmboy/hosts')
  hosts = []
  hosts.append('127.0.0.1 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:
        continue

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

    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)

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

    print ('Alright! Check out your site at: http://%%s'
            %% util.host(env.roledefs['proxy'][0]))
Exemple #3
0
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()`
env.roledefs.update(%(roledefs)s)

# 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