Fabric is a command-line-based automated deployment framework for Python that uses Docker to open two of containers to learn fabric.
#!/usr/bin/env python#-*-coding=utf-8-*-from fabric.api import *env.hosts=[ ' [email protected]:22 ', ' [email Protected]:32 ',]env.passwords={ ' [email protected]:22 ': ' * * * * *, ' [email protected]:32 ': ' * * * ',} @taskdef Task1 (): run (' ps ') @taskdef task2 (): run (' uname-a ') @taskdef dotask (): execute (TASK1) Execute ( TASK2)
Execution results
[email protected]:/home# Fab dotask[[email protected]:22] Executing task ' dotask ' [[email protected] : Executing task ' task1 ' [[[email protected]:22] run:ps[[email protected]:22] out:pid TTY time CMD [[email protected]:22] out:26424 pts/2 00:00:00 ps[[email protected]:22] out:[[email protected]:32] Executing task ' task1 ' [[[email protected]:32] run:ps[[email protected]:32] out:pid TTY time Cmd[[ema IL PROTECTED]:32] out:59 pts/0 00:00:00 ps[[email protected]:32] out:[[email protected]:22] Executin G Task ' Task2 ' [[email protected]:22] run:uname-a[[email protected]:22] Out:linux Iz2893wjzgyz 3.13.0-32- Generic #57-ubuntu SMP Tue Jul 03:51:08 UTC x86_64 x86_64 x86_64 gnu/linux[[email protected]:22] out:[[email& NBSP;PROTECTED]:32] Executing task ' task2 ' [[email protected]:32] run:uname-a[[email protected]:32] out: Linux c368a2768e6b 3.13.0-32-generic #57-ubuntU SMP Tue Jul 03:51:08 UTC x86_64 x86_64 x86_64 gnu/linux[[email protected]:32] Out:[[email protected]:3 2] Executing task ' dotask ' [[[email protected]:22] executing task ' task1 ' [[email protected]:22] Run:ps[[email  PROTECTED]:22] Out:pid TTY time cmd[[email protected]:22] out:26447 pts/2 00:00:00 PS[[EMAIL&NB SP;PROTECTED]:22] out:[[email protected]:32] executing task ' task1 ' [[email protected]:32] Run:ps[[email  PROTECTED]:32] Out:pid TTY time cmd[[email protected]:32] out:63 pts/0 00:00:00 PS[[EMAIL&NB SP;PROTECTED]:32] out:[[email protected]:22] executing task ' task2 ' [[email protected]:22] run:uname-a[[ EMAIL PROTECTED]:22] Out:linux Iz2893wjzgyz 3.13.0-32-generic #57-ubuntu SMP Tue Jul 03:51:08 UTC x86_64 x86 _64 x86_64 gnu/linux[[email protected]:22] out:[[email protected]:32] executing task ' task2 ' [[email PROTECTED]:32] Run:uname-a[[email protected]:32] Out:linux c368a2768e6b 3.13.0-32-generic #57-ubuntu SMP Tue Jul 03:51:08 UTC x86_64 x86_64 x86_64 GNU/Linux [[email protected]:32] Out:done. Disconnecting from 114.215.86.228 ... Done. Disconnecting from 114.215.86.228:32 ... Done.
However, the password is plaintext and unsafe, so it is still recommended to manage the server with the addition of a key.
- This article is from a good Linux tutorial network
Fabric bulk operation of remote operations master exercises