Created
September 19, 2017 16:19
-
-
Save anandology/6a955f48f5ae79837a5071656e7fd5ef to your computer and use it in GitHub Desktop.
Fabric demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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