Jaime Frutos Morales's blog

06/04/2010

How to install and use Fabric on Ubuntu 9.10

Filed under: Python, SysAdmin, Ubuntu — acidborg @ 10:59

From its web: “Fabric is a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. More specifically, Fabric is:

  • A tool that lets you execute arbitrary Python functions via the command line;
  • A library of subroutines (built on top of a lower-level library) to make executing shell commands over SSH easy and Pythonic.

Naturally, most users combine these two things, using Fabric to write and execute Python functions, or tasks, to automate interactions with remote servers.

Installation:

  1. Download the package from here
  2. Install it: sudo dpkg -i fabric*.deb

Use::

  1. Follow this short tutorial to learn the basics.
  2. Create a file called fabfile.py
  3. Fill it with your customized functions. For Example:
    from fabric.api import env, run, sudo
    env.hosts = ['ubuntu1', 'ubuntu2', 'ubuntu3']
    def upgrade_hosts():
    sudo('apt-get update && apt-get dist-upgrade ')
  4. Run fabric: fab upgrade_hosts

I find Fabric very useful and time-saving when maintaining similar servers, because you can design a task and run it automatically on all the servers.

Advertisements

Blog at WordPress.com.

%d bloggers like this: