Executing your first Fabric file

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 root access123
CentOS 7.4 root access123

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.