DevOps: Introduction to Fabric.
In this post, we will introduce Fabric.
Fabric is a simple, yet powerful, tool for remotely controlling a farm of servers from your terminal.
As a warmup example, let’s assume that you want to check the uptime of a list of servers, say server1.example.com, server2.example.com, …, serverN.example.com.
Of course, you can always write a bash script as the one below to do so,
A curious reader might ask why to bother using fabric or any other tool for the above operation?
An answer to this question is that fabric focuses on what are the operations to be performed on the servers whereas the above script has to be also concerned of how the tasks will be executed. For example, how would you run the above for loop
in parallel? Using fabric is quite simple, see parallel fabric for more details.
Next, we describe how to install fabric and then how to configure it for the above uptime task.
Installing Fabric
To install fabric, you first need to ensure that you have Python installed, and also install python pip. Then, to instal fabric simply do
Configuring Fabric
Configure fabric is straightforward. Simply create a fabfile.py
in you current directory with the following content. Also create a server.txt
with its i-th line equal to server{i}.example.com
.
Running Fabric
To run fabric, simply do
To execute fabric in parallel, you can simple do
See parallel fabric for more details on parallel execution.