Reputation: 97
I just spent a lot of time trying to follow the basics of using fabric to establish a connection to a remote machine. I'm using a raspberry pi 3, it has python 2.7 installed on it, and fabric 1.13.1. I can successfully run a hello world function using a fabfile, but can't actually write a python script that establishes a connection to a remote machine, whether in the live python debugger or in a standalone python file. I dont even try to establish the connection. I just try to import Connection from fabric. Example:
from fabric import Connection
or
import fabric
c = fabric.Connection("192.168.0.1")
This always results in the error:
AttributeError: 'module' object has no attribute 'Connection'
I'm not sure what to do. When I look inside the directory of the fabric source, there is nothing named Connection. What am I doing wrong here?
Note: I am following the tutorial at: http://www.fabfile.org/
Upvotes: 0
Views: 1397
Reputation: 472
You are using Fabric v.1.X, in which the API is not OO, and the fabric
module doesn't even have a Connection
attribute.
In order to benefit from the Connection
attribute, you have to use fabric v2.X, which is the version documented in fabfile.org
However, this version is not compatible with Python 2.X
If you really need to stick with Python 2.X, you have to use the env
dictionary
from fabric.api import env
env.hosts = ['192.168.0.1']
# Your remaining code here
For more info, please refer to Fabric 1.13 docs here
Upvotes: 1