Reputation: 324
I'm running a small code that uses fabric's rsync_project
function to connect to a remote machine and transfer a file to it. I've assigned env.password
with the password of the server.
However, when I run the code, I get prompted for password. After entering the password, the file gets transferred. But I do not want to get prompted.
Here's my code:
from fabric import environment
from fabric.contrib.project import rsync_project
env.hosts = ['172.16.154.134']
env.password = 'user@123'
def sync(remote_dir, local_dir):
rsync_project(remote_dir, local_dir)
Maybe I have misunderstood what env.password
is for. If so, please tell me some other way to get rid of the prompt that asks for password.
Thanks
Upvotes: 0
Views: 1153
Reputation: 15926
This is a common misunderstanding. Once you set env in code, whatever function you call should be called with execute
.
from fabric.state import env
from fabric.decorators import task
from fabric.api import execute
from fabric.contrib.project import rsync_project
env.hosts = ['172.16.154.134']
env.password = 'user@123'
def internal_sync(remote_dir, local_dir):
rsync_project(remote_dir, local_dir)
# use task to define the external endpoint for the fab command line
@task
def sync(remote_dir, local_dir):
"""Does an rsync from remote_dir => local_dir"""
# above docstring for `fab --list`
# call `internal_sync` using the env
# parameters we set in code
execute(internal_sync, remote_dir, local_dir)
And from the command line:
fab sync:/path/to/remote,/path/to/local
Upvotes: 1