Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple Fabfile for creating and installing a LAMP server on HP Cloud.
from fabric.api import *
# Keyfile for SSH. Use this if you're not
# using SSH Agent.
env.key_filename = "~/.ssh/hpcompute.pem"
@task
def hello():
puts("Hello")
@task
def create_server(name):
"""Create a new HP Cloud server."""
image = 81078 # Ubuntu 12.04 in AZ-1
flavor = 100 # extra-small
security_group = 'Web'
key = 'hpcompute'
# This is the local command we'll run.
template = "hpcloud servers:add %s %s -i %s -k %s -s %s"
cmd = template % (name, flavor, image, key, security_group)
local(cmd)
@task
def destroy_server(name):
"""Destroy an HP Cloud server."""
local("hpcloud servers:remove %s" % name)
@task
def server_details(name = ''):
"""Get the server details."""
local("hpcloud servers %s" % name)
@task
def install_lamp():
"""Install a LAMP stack on the server."""
# Install the packages
sudo("apt-get -q update")
packages = "apache2 mysql-server libapache2-mod-php5 php5-mysql"
sudo("apt-get install -q %s" % packages)
# Push the index.php file to the server and get rid of
# the old index.html file.
put("index.php", "/var/www/index.php", use_sudo=True)
sudo("rm /var/www/index.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.