Python Fabric


Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.



 yum install fabric


 pip install fabric


I plan on using Fabric as a push-to config management service which will work very nicely as a secondary piece to my CFEngine setup. I used this to deploy a security update to 120+ hosts in under 20 minutes.


 ]# fab -H server001 -- yum -y update glibc # will ask for password

With fabfile

one can create a with default settings and expanded tasks to execute, also paralled task execution can be achived.

 ]# vim
 from fabric.api import *
 from fabric.contrib.files import *
 env.hosts = [
 env.user = "root" #it runs as parallel operations so there is no chance to enter a password for sudo users
 env.password = ""
 def install():
         run("yum -y update glibc")

Then to run:

 ]# fab -P install -f

Advanced concepts

The following is more advanced options that can be included within a fabfile in order to achieve different results.

env.roledefs = {
      'testing': [
 ]# fab install:roles=testing
def disk_check():
        run("df -hl")

def ram_check():
        run("free -h")

def check_all():
        print("Executing on %s as %s" % (, env.user))
        upload_template("/tmp/fabric_hello", "/var/tmp/fabric_hello")# source, destination
 ]# fab check_all:roles=testing 

will run all tasks in order on each machine, do not use parallel execution if you expect to use the results returned to screen in anyway as parallel stdout/stderr does not return in order.