Install Fabric on Raspberry Pi – Raspbian Jessie and Stretch

Install Fabric on Raspberry Pi – Raspbian Jessie and Stretch

This manual is for fabric and not for fabric2 or fabric3!

You have set up a Raspbian Pi cluster, but you don’t know how to manage it easily.
We use Fabric, so we can send commands very fast and easy to all computers in the cluster.

With this manual I assume that you have noted down all IP addresses of the Raspberries in the cluster.

We have a fresh Raspbian installation.

IP addresses given in this manual must of course be exchanged by you for your IP addresses.

My IP addresses are :

# Cluster # Host 1 / User: pi # Host 2 / User: pi # Host 3 / User: pi # Host 4 / User: pi

In total we have 5 Raspberry Pi, one of which takes control.
At this, is also connected a mouse, keyboard and a monitor.
All computers in the cluster have the same name (pi) and password.
Here we will also install Fabric.

First we update our system with the following command :

sudo apt-get update -y 
sudo apt-get upgrade -y


Now we still need some libraries, which we download from the net with the following command :

sudo apt-get install build-essential \
    tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev \
    libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev \ 
    libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y \

Now we install Fabric with the following command :

sudo apt-get install fabric

Fabric is now installed and we can create a command file named „“.
We enter the following commands :

# change to home directory

# This command when we have loaded the Graphical User Interface
sudo leafpad

# Or this command if we have not loaded the Graphical User Interface
sudo nano

We fill the file with the following commands :
(This is just an example, how you do this later to make your work more efficient is up to you.)

# Import Fabric's API module
from fabric.api import *
from fabric.colors import green

# My User Name and my IP adresses
# You're gonna have to replace that with your own.
env.hosts = [

# All Raspberrys have the same password 
# Here too, replace it with your password
env.password = "yourPassword"
def check():
    # check host type
    # Check diskspace

def cmd(command):
def allshutdown():
	sudo("shutdown -t 1") #shutdown in 1 min

def allreboot():
	sudo("shutdown -r -t 1") #reboot in 1 min

def allcancel():
        sudo("shutdown -c") #cancel the last shutdown command

def alldate():
        sudo("date +\"Date : %d/%m/%Y Time : %H.%M.%S\"") #show Time and Date

# You can customize the file according to your needs.
# If you're not so good with Pyhton yet, learn it, 
# it's a wonderful programming language.

Now you can send your commands from the terminal to all the computers you specified above, for example :

fab cmd:"dir"

Or this to shut down all the computers in 1 min.

fab allshutdown

Or this to cancel shutdown.

fab cmd:"shutdown -c"

You can find more information at :

So that’s it, I hope I could help.
Write your own commands and your life will be easier.

Das könnte dich auch interessieren …

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.