Automate Devops

Automate devops with Fabric

This “recipe” allows “remote” Dev-Ops from a local machine with Fabric 2.3.1.

One way is to pip install fabric.

Creating a fabric fabfile:

from fabric import Connection
from fabric import task

def space(c):
    result ='df -h')

def devops(c):

The fabfile reads ~/.ssh/config, where the Host: web1 ( is configured.

Set up the hosts to automate: cat ~/.ssh/config

Host web1
  User foobar
  # or identyfile:
  # IdentitiesOnly yes
  # IdentityFile ~/.ssh/web1

The -H flag is the Host of ssh-config and devops the task:

fab --prompt-for-login-password -Hweb1 devops

Enter login password for use with SSH auth: 

Filesystem      Size  Used Avail Use% Mounted on
dev             1.8G     0  1.8G   0% /dev
run             1.8G  1.6M  1.8G   1% /run
/dev/sda3       233G  192G   29G  87% /
Written on September 7, 2018
[ ]