Reboot a remote host with Fabric

Boris HUISGEN
Boris HUISGEN
Reboot a remote host with Fabric

It is sometimes difficult to only reboot a host with Fabric.

The reboot operation provided by Fabric being dysfunctional and deprecated, it is necessary to use a manual and safe method:

1from fabric.state import *
2
3def mytask:
4    sudo("shutdown -r +1")
5    time.sleep(120)
6    connections[env.host_string].get_transport().close()
7    run("uptime")

The waiting period can be adapted to the need, but disconnection to the host is required so that Fabric can re-establish the SSH tunnel.

Boris HUISGEN
Boris HUISGEN
Blog owner
  • #fabric