wroscoe
wroscoe

Reputation: 2014

Always given command line before python fabric command is executed on remote

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

Upvotes: 0

Views: 627

Answers (2)

wroscoe
wroscoe

Reputation: 2014

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

Upvotes: 1

Dmitry
Dmitry

Reputation: 337

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.

Upvotes: 1

Related Questions