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-*- fromFabric.apiImport*env.hosts=[ '[Email protected]:22', '[Email protected]:32',]env.passwords={ '[Email protected]:22':'*****', '[Email protected]:32':'***',} @taskdefTask1 (): Run (' PS') @taskdefTask2 (): Run (' Uname-a') @taskdefdotask (): Execute (TASK1) execute (TASK2)
Execution results
[Email Protected]:/home#Fab dotask[[Email protected]:22] Executing task'Dotask'[[Email protected]114.215.86.228:22] Executing task'Task1'[[Email protected]114.215.86.228:22] Run:ps[[email protected]114.215.86.228:22] Out:pid TTY time Cmd[[email protected]114.215.86.228:22] out:26424 PTS/2 00:00:00Ps[[email protected]114.215.86.228:22] Out:[[email protected]114.215.86.228:32] Executing task'Task1'[[Email protected]114.215.86.228:32] Run:ps[[email protected]114.215.86.228:32] Out:pid TTY time Cmd[[email protected]114.215.86.228:32] out:59 pts/0 00:00:00Ps[[email protected]114.215.86.228:32] Out:[[email protected]114.215.86.228:22] Executing task'Task2'[[Email protected]114.215.86.228:22] Run:uname-A[[email protected]114.215.86.228: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]114.215.86.228:32] Executing task'Task2'[[Email protected]114.215.86.228:32] Run:uname-A[[email protected]114.215.86.228: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]114.215.86.228:32] Executing task'Dotask'[[Email protected]114.215.86.228:22] Executing task'Task1'[[Email protected]114.215.86.228:22] Run:ps[[email protected]114.215.86.228:22] Out:pid TTY time Cmd[[email protected]114.215.86.228:22] out:26447 PTS/2 00:00:00Ps[[email protected]114.215.86.228:22] Out:[[email protected]114.215.86.228:32] Executing task'Task1'[[Email protected]114.215.86.228:32] Run:ps[[email protected]114.215.86.228:32] Out:pid TTY time Cmd[[email protected]114.215.86.228:32] out:63 pts/0 00:00:00Ps[[email protected]114.215.86.228:32] Out:[[email protected]114.215.86.228:22] Executing task'Task2'[[Email protected]114.215.86.228:22] Run:uname-A[[email protected]114.215.86.228: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]114.215.86.228:32] Executing task'Task2'[[Email protected]114.215.86.228:32] Run:uname-A[[email protected]114.215.86.228: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 from114.215.86.228... done . Disconnecting from114.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.
Fabric bulk operation of remote operations master exercises