|
From: | Michael Maley |
Subject: | [Fab-user] How do I use Fabric to SSH to two different ports on the same server? |
Date: | Thu, 16 Feb 2012 10:01:16 -0500 |
Disclaimer: Newb Python/Fabric user here. I’m trying to use Fabric to deploy Karaf on a collection of servers. This means I have to remotely connect to the same servers via SSH on two different ports. The first SSH is into the server to retrieve and install the packages for Karaf and the second SSH is into Karaf itself, which starts on port 8101 by default. When I do so, using execute(), it works quite well, but all actions after connecting to the second SSH port are executed as the ‘karaf’ user on port 8101 rather than as the original user. This forces me to have the Karaf connection be the very last thing I do before disconnecting. To illustrate, here’s my simple example with sample output (hopefully) demonstrating the hijacking of env.user 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) Sample output: ~/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 address@hidden:8101] Executing task 'secondSSH' address@hidden:8101] run: echo second address@hidden:8101] Login password: address@hidden:8101] out: second address@hidden:8101] run: echo first again Done. Disconnecting from 192.168.5.250:8101... done. Disconnecting from address@hidden done. I’d really like the tasks after the execute() to run as the original user (mmaley). Am I doing something incorrectly, or is this a limitation of how the context gets passed into/out of execute()? Thanks in advance for any help/tutelage anyone can provide. |
[Prev in Thread] | Current Thread | [Next in Thread] |