i remember fabric API can be called directly in py script but forgot where to start anybody give a clue?
Yes, you can call it, for example:
from fabric.api import run
from fabric.tasks import execute
def do_something():
run("echo $RANDOM")
if __name__ == "__main__":
execute(do_something, hosts=["username@host"])
There is a whole section on using fabric as a library in the docs. I'd refer to that and how best to approach fabric's use in this way.
Specifically, you'll want to address the problem of performing task X
on a list of hosts Y
by using the execute function as execute( X, hosts=Y )
. When you are done, you should disconnect from all of the connected hosts. Normally the fab
tool does this for you, but you must do this manually when using fabric as a library. Fabric 0.9.4 and later have a disconnect_all()
function. Ideally, this should be in the finally
clause of a try...finally
statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With