I am trying to use Fabric (v1.3.4) to provide instances of Karaf on different servers. Karaf implements an SSH server. So, I have 2 ssh daemons running on the same server; one on port 22 and one on 8101. Using the fabric.tasks.execute () Fabric method, I can connect to an alternate host: port.
The problem is that my original session was hijacked by the named user of the second connection due to the explicit hijacking of env.user.
Here's a simplified example of fabfile.py:
from fabric.api import env, run from fabric.tasks import execute env.hosts = ['192.168.5.250'] def firstSSH(): run("echo first") executeHosts = [] for host in env.hosts: executeHosts.append(" notmmaley@ " + host + ":8101") execute(secondSSH, hosts=executeHosts) run("echo first again") def secondSSH(): run("echo second", shell=False, pty=False)
Both SSH servers are located on the same server with two different ports and allow the use of two different users. Here is the result:
~/fabric$ fab firstSSH [192.168.5.250] Executing task 'firstSSH' [192.168.5.250] run: echo first [192.168.5.250] Login password: [192.168.5.250] out: first [ notmmaley@192.168.5.250 :8101] Executing task 'secondSSH' [ notmmaley@192.168.5.250 :8101] run: echo second [ notmmaley@192.168.5.250 :8101] Login password: [ notmmaley@192.168.5.250 :8101] out: second [ notmmaley@192.168.5.250 :8101] run: echo first again Done. Disconnecting from 192.168.5.250:8101... done. Disconnecting from mmaley@192.168.5.250... done.
Note how "echo first again" is executed as the user notmmaley, which has been strictly defined for the hosts of the execute () command. What I want (need) is to execute the execute () command as the named user for the specified user port user @host :, and then return the original user to me for the rest of the tasks. Is this possible with Fabric / execute () and / or where did I go wrong?
mmaley
source share