Automation of remote operations with Fabric

Use the IT automation library fabric (made by python).

fabric must be used with python2.5-2.7 (not compatible with python3)

Using fabric is very easy:

  1. Create a function func () for the operation you want to perform in fabfile.py
  2. On terminal, run $ fab func

Use pip to install fabric

$ pip install fabric

1. Create an execution script

$ sudo nano fabfile.py

fabfile.py


# coding: utf-8
from fabric.api import env, run, sudo

env.hosts = ["192.168.11.161",
             "192.168.11.162",
             "192.168.11.163",
             "192.168.11.164"]
env.user = "pi"
env.password = "raspberry"

def hello():
    run("ifconfig wlan0")
    run("ls")

def fix_100m_full():
    sudo("ethtool -s eth0 autoneg off speed 100 duplex full")
    sudo("ethtool eth0")

2. Run fabric

Check for executable tasks

$ fab -l

hello
fix_100m_full

Run task (try running an automatic script that turns off Auto-negotiation)

#$ fab <Task name>
$ fab fix_100m_full | grep Auto-nego

[192.168.11.161] out: 	Auto-negotiation: off
[192.168.11.162] out: 	Auto-negotiation: off
[192.168.11.163] out: 	Auto-negotiation: off
[192.168.11.164] out: 	Auto-negotiation: off

reference

http://fabric-ja.readthedocs.io/ja/latest/tutorial.html

Recommended Posts

Automation of remote operations with Fabric
Automation of server monitoring etc. with Monit
Summary of operations often performed with asyncpg
[Python] Summary of S3 file operations with boto3
Scripting with Paver-File Operations
File operations with open — "../"
Summary of string operations
Ssh to virtual environment with remote development of vscode
The true value of Terraform automation starting with Oracle Cloud
Remote L Chika with pigpio
Summary of python file operations
Summary of Python3 list operations
Equation of motion with sympy
Fast file transfer with fabric
Perform logical operations with Perceptron
Parallel processing with Parallel of scikit-learn
Prediction of Nikkei 225 with Pytorch 2
Memories of fighting with Selenium
Prediction of Nikkei 225 with Pytorch
Remote debugging with Visual Studio 2017
Do multi-stage SSH with Fabric
I tried standalone deployment of play with fabric [AWS operation with boto] [Play deployment]