fabric is a tool for system administration/DevOps. It allows you to manage multiple servers with single command.
You can find more information about fabric at
fabric work over SSH, using SSH Keys. No special software needed to be install on server side. To install fabric on Ubuntu, run
$ sudo pip install fabric [sudo] password for boby: Downloading/unpacking fabric Downloading Fabric-1.10.2-py2-none-any.whl (90kB): 90kB downloaded Downloading/unpacking paramiko>=1.10 (from fabric) Downloading paramiko-1.15.3-py2.py3-none-any.whl (166kB): 166kB downloaded Requirement already satisfied (use --upgrade to upgrade): pycrypto>=2.1,!=2.4 in /usr/lib/python2.7/dist-packages (from paramiko>=1.10->fabric) Downloading/unpacking ecdsa>=0.11 (from paramiko>=1.10->fabric) Downloading ecdsa-0.13-py2.py3-none-any.whl (86kB): 86kB downloaded Installing collected packages: fabric, paramiko, ecdsa Successfully installed fabric paramiko ecdsa Cleaning up... $
To use fabric, you need to create a fabfile.py, here is my fabfile.py
$ cat fabfile.py from fabric.api import env from fabric.api import run env.hosts = ['s20n','s46n','s48n','s74n'] env.user = 'root' env.port = 3333 def uptime(): run('uptime') def mailq(): run('exim -bpc') def eximrm(): run('eximrm') def df(): run('df -h') def uname(): run('uname -r') def upgrade(): run('yum upgrade -y') def honcpanel(): run('cd /usr/honcpanel && git pull origin master');
To run uptime on all servers, i run
fabric will run the command defined in mailq() function on all servers you specified in the file and display the result.
[email protected]:~/www/fabric $ fab uptime [s20n] Executing task 'uptime' [s20n] run: uptime [s20n] out: 04:58:19 up 1 day, 10:15, 1 user, load average: 0.53, 0.76, 0.91 [s20n] out: [s46n] Executing task 'uptime' [s46n] run: uptime [s46n] out: 04:58:21 up 10 days, 21:12, 1 user, load average: 2.08, 1.94, 2.04 [s46n] out: [s48n] Executing task 'uptime' [s48n] run: uptime [s48n] out: 04:58:32 up 2 days, 1:27, 1 user, load average: 4.90, 5.75, 5.82 [s48n] out: [s74n] Executing task 'uptime' [s74n] run: uptime [s74n] out: 04:58:37 up 1 day, 10:27, 1 user, load average: 1.04, 1.25, 1.37 [s74n] out: Done. Disconnecting from s48n:3333... done. Disconnecting from s46n:3333... done. Disconnecting from s74n:3333... done. Disconnecting from s20n:3333... done. [email protected]:~/www/fabric $