Skip to content

Instantly share code, notes, and snippets.

@anandology
Created September 19, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/6a955f48f5ae79837a5071656e7fd5ef to your computer and use it in GitHub Desktop.
Save anandology/6a955f48f5ae79837a5071656e7fd5ef to your computer and use it in GitHub Desktop.
Fabric demo
"""Fabric demo.
Setup Instructions:
pip install Fabric3
How to use:
fab --list
fab hello
fab provision
fab venv
fab wc:filename=fabfile.py
"""
from fabric.api import task, run, sudo, cd, env, get, put
import os
env.hosts = ["pipal.in"]
@task
def hello():
"""Prints hello world message.
"""
run("w > /tmp/w.txt")
getf
@task
def wc(filename):
put(filename, "/tmp")
run("wc /tmp/{} > /tmp/wc.txt".format(os.path.basename(filename)))
get("/tmp/wc.txt", "wc.txt")
print(open("wc.txt").read())
@task
def venv():
sudo("mkdir -p /usr/local/vikrant")
sudo("virtualenv /usr/local/vikrant/venv")
with cd("/usr/local/vikrant/venv"):
sudo("./bin/pip install Django")
APT_PACKAGES = [
"python-virtualenv"
]
@task
def provision():
sudo("apt-get update")
sudo("apt-get install -y " + " ".join(APT_PACKAGES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment