Friday, April 25, 2014

Fabric - Pythonic remote execution

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.

It provides a basic suite of operations for executing local or remote shell commands (normally or via sudo) and uploading/downloading files, as well as auxiliary functionality such as prompting the running user for input, or aborting execution.

Typical use involves creating a Python module containing one or more functions, then executing them via the fab command-line tool. 

How to install fabric on Linux Boxes.

Fabric is best installed via pip (highly recommended) or easy_install (older, but still works fine), e.g.:
$ pip install fabric
You may also opt to use your operating system’s package manager; the package is typically called fabric or python-fabric. E.g.:
$ sudo apt-get install fabric
Advanced users wanting to install a development version may use pip to grab the latest master branch (as well as the dev version of the Paramiko dependency):
$ pip install paramiko==dev
$ pip install fabric==dev


In order for Fabric’s installation to succeed, you will need four primary pieces of software:
  • the Python programming language;
  • the setuptools packaging/installation library;
  • the Python Paramiko SSH library;
  • and Paramiko’s dependency, the PyCrypto cryptography library.
and, if using the parallel execution mode:
If you’re using Paramiko 1.12 or above, you will also need an additional dependency for Paramiko:
Below are my 2 fabfile

To run get_version on both roles (webservers and databases);

fab get_version

No comments: