Neeran
Neeran

Reputation: 1793

Fabric ssh twice within host

How do I ssh twice if server2 can only be accessed from server1?

fabfile.py:

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

env.hosts = ['[email protected]']

env.use_ssh_config = True

def dothis():
    run('ssh [email protected]')
    run('ls -al') # this should be done on [email protected]

When I run:

fab dothis, I get:

[[email protected]] Executing task 'dothis'
[[email protected]] run: ssh [email protected]
[[email protected]] out: Permission denied (publickey).
[[email protected]] out: 
[[email protected]] out: 

Fatal error: run() received nonzero return code 255 while executing!

Requested: ssh [email protected]
Executed: /bin/bash -l -c "ssh [email protected]"

Aborting.
Disconnecting from [email protected]... done.

How do I tell fabric to env.user_ssh_config = True on server2 without keeping another fabric file on server1?

The way I usually access server2 is like this:

ssh [email protected] ssh [email protected]

Upvotes: 2

Views: 2144

Answers (1)

johnsyweb
johnsyweb

Reputation: 141780

It looks like you're trying to use "server1.com" as a gateway host to "server2.com", and presumably others:

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

env.gateway = '[email protected]'
env.hosts = ['[email protected]']

env.use_ssh_config = True

def dothis():
    run('ls -al')  # this should be done on [email protected]

Upvotes: 1

Related Questions