We now know how the operation works, so we will put it inside fabfile and create a full automation script that can work with remote machines. The first step for fabfile is to import the required classes. Most of them are located in fabric.api, so we will globally import all of them to our Python script:
from fabric.api import *
The next part is to define the remote machine IP addresses, usernames, and passwords. In the case of our environment, we have two machines (besides the automation server) that run Ubuntu 16.04 and CentOS 7.4, respectively, with the following details:
Machine Type | IP Address | Username | Password |
Ubuntu 16.04 | 10.10.10.140 | root | access123 |
CentOS 7.4 | 10.10.10.193 | root | access123 |