2

I am unable to understand how should I set username, password, ip and port for my remote host in python fabric. I followed this. But the docs only explains like below:

from fabric.api import run
from fabric.api import env

env.hosts = [
    'newyork',
    'seattle',
    'localhost',
    ]

def host_type():
    run('uname -s')

def diskspace():
    run('df')

I wonder how they are connecting to the hosts network etc without giving any connection or credential information?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
qurat
  • 439
  • 1
  • 7
  • 14

1 Answers1

0

Have you checked: http://docs.fabfile.org/en/1.10/usage/fab.html

You should use as a rule of thumb in SSH, SSH keys not password.

https://stackoverflow.com/a/5568219/1152669

from fabric import env
env.hosts = ['user1@host1:port1', 'user2@host2.port2']
env.passwords = {'user1@host1:port1': 'password1', 'user2@host2.port2': 'password2'}
Community
  • 1
  • 1
  • Why e.v.hosts and env.passwords are separate? Can't I write like, env.hosts = {'user1@host1:port1': 'password1', 'user2@host2.port2': 'password2'} – qurat Feb 20 '16 at 10:15
  • I tried you suggestion this way, env.hosts = [username+'@'+host+':'+port] env.passwords = {username+'@'+host+':'+port: password}, but it is giving me a syntax error at colon – qurat Feb 20 '16 at 10:28
  • sorry my mistake. I was using square brackets instead of curly while setting up env.passwords – qurat Feb 20 '16 at 10:51