Python Fabric Example

Do you like this?

Summary:
This short example shows you how to use Fabric library


Content:

1. Installing Fabric

Run this command: easy_install fabric
On Windows machine, you might encounter errors setting up Paramiko (a dependency of Fabric) since it cannot find vcvarsall.bat file. What you can do is downloading a setup file from Voidspace and then install Paramiko using the file. Then you can run easy_install fabric again.

2. Creating A fabfile.py In Your Project's Folder

A sample code is provided below:
from fabric.api import *

env.host_string = "yourserver.com"
env.user="username"
env.password= "pass"

def ls():
    run("ls -l")

3. Run Fabric

Open a console and cd to your project's folder. And run the following command:
fab ls
Fabric will then call the ls() method in your fabfile.py and return the directory information to your output.

 
comments powered by Disqus