0

I'm just starting to use python fabric to run commands on remote rackspace ubuntu servers. I can't run a command without getting the command line requiring my input. This is the sequence how I can recreate the problem.

I do not have any trouble connecting to the remote machine with ssh using keys and no passwords.

This is my fabfile.py

from fabric.api import env, run

env.hosts = ['remote.ip.address']
env.user = 'http'

def hello():
    run("touch hello.world")

The command I use to run the fabfile.py (uses python 2.7 virtualenv)

$ ~/env/py27/bin/fab -f code/fabfile.py hello

This is the command line showing how it always gets stuck and requires me to type exit.

[remote.ip.address] Executing task 'hello'
[remote.ip.address] run: touch hello.world
[remote.ip.address] out: http@server-name:~$ 

I can exit the remote terminal by typing exit and the command will run and I'll be returned to my local terminal.

[remote.ip.address] out: exit
[remote.ip.address] out: 

Done.
Disconnecting from remote.ip.address... done.
me@local-computer: $ 

And this is the method I used to set up ssh keys to not require passwords. https://kb.mediatemple.net/questions/1626/Using+SSH+keys+on+your+server

wroscoe
  • 1,914
  • 3
  • 19
  • 18
  • 1
    yeah this is kinda weird... did you try setting the host string in the code? See Toby Champion's answer [here](http://stackoverflow.com/questions/2326797/how-to-set-target-hosts-in-fabric-file) for what I mean – Greg Sep 13 '13 at 08:23
  • Just ran through this exact code as well on a fresh Ubuntu box. I do have to wait for a bit for it to run. I did add env.password, I could test with keys next. – Kyle Kelley Sep 13 '13 at 15:26
  • Edited Question to include the method I used to set up SSH keys. I'm not sure whats causing this to fail. – wroscoe Sep 14 '13 at 00:24

2 Answers2

1

Interesting, I don't have such issue, your code works fine for me (up to adding env.key_filename and env.password)

c:\work>fab hello
[x.x.x.x] Executing task 'hello'
[x.x.x.x] run: touch hello.world

Done.
Disconnecting from x.x.x.x... done.

I'm using Fabric 1.7.0 and Paramiko 1.11.0. Possibly it's a problem of the terminal on your server.

Dmitriy
  • 340
  • 2
  • 9
1

Ok I figured it out.

I had edited my ~/.profile file to inclue the "bash" command so that bash would be the default shell. I've copied the old version of the ~/.profile file below. Since fabric leads all of its commands with /bin/bash it was essentially starting two bash prompts and only exiting one. After I removed the bash command from the server everything works fine.

This is the bash file with the extra bash command.

bash  #REMOVE THIS LINE AND FABRIC WORKS

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
wroscoe
  • 1,914
  • 3
  • 19
  • 18