failed to open a SFTP connection, -c ssh connects but gives me errors

4,701 views
Skip to first unread message

nflacco

unread,
Nov 16, 2012, 7:24:53 PM11/16/12
to ansible...@googlegroups.com
I'm having trouble with paramiko/sftp, and using the -c ssh option gets me one step further but still results in an error. I've been running on OSX but created a fresh LinuxMint VM in VirtualBox with all the latest and greatest stuff, and duplicated the issues I saw in OSX. The -c ssh looks slightly different though. For reference, I'm running python 2.7 on both Linux and OSX, and I'm trying to access an EC2 instance.

I've tried executing a simple shell command (-m shell -a 'echo "HELLO") and a ping (-m ping). I have also tried a simple playbook and gotten the same errors.

LinuxMint (VM), Pyth

Paramiko

$ansible prod --user=ec2-user --private-key=key.pem -m shell -a 'echo "Hello"'
www.myserver.com | FAILED => failed to open a SFTP connection

SSH

$ansible prod --user=ec2-user --private-key=key.pem -m shell -a 'echo "Hello"' -c ssh
prod1.v2.pixieplug.com | FAILED => failed to transfer file to /home/ec2-user/.ansible/tmp/ansible-1353110320.71-241956472283584/command:

Couldn't read packet: Connection reset by peer

OSX

Paramiko

$ansible prod --user=ec2-user --private-key=key.pem -m shell -a 'echo "Hello"'
prod1.v2.pixieplug.com | FAILED => failed to open a SFTP connection

SSH

$ansible prod --user=ec2-user --private-key=key.pem -m shell -a 'echo "Hello"' -c ssh
www.myserver.com | FAILED => failed to transfer file to /home/ec2-user/.ansible/tmp/ansible-1353110453.09-107376501006560/command:
Connecting to www.myserver.com...
// motd that I expect from my server, so it got in //
subsystem request failed on channel 0
Connection closed

OSX, Playbooks

Paramiko

$ansible-playbook test.yml --user=ec2-user --private-key=key.pem
PLAY [prod] ********************* 
GATHERING FACTS ********************* 
fatal: [www.myserver.com] => failed to open a SFTP connection
TASK: [print hello world] ********************* 
FATAL: no hosts matched or all hosts have already failed -- aborting

PLAY RECAP ********************* 
www.myserver.com         : ok=0    changed=0    unreachable=1    failed=0    


SSH 

ansible-playbook test.yml --user=ec2-user --private-key=key.pem -c ssh
PLAY [prod] ********************* 
GATHERING FACTS ********************* 
fatal: [www.myserver.com] => failed to transfer file to /tmp/ansible-1353111690.46-131535236804596/setup:
Connecting to www.myserver.com...
// motd //
subsystem request failed on channel 0
Connection closed
TASK: [print hello world] ********************* 
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************* 
www.myserver.com         : ok=0    changed=0    unreachable=1    failed=0

Romeo Theriault

unread,
Nov 16, 2012, 9:22:03 PM11/16/12
to ansible...@googlegroups.com
On Fri, Nov 16, 2012 at 2:24 PM, nflacco <nico....@gmail.com> wrote:
> I'm having trouble with paramiko/sftp, and using the -c ssh option gets me
> one step further but still results in an error. I've been running on OSX but
> created a fresh LinuxMint VM in VirtualBox with all the latest and greatest
> stuff, and duplicated the issues I saw in OSX. The -c ssh looks slightly
> different though. For reference, I'm running python 2.7 on both Linux and
> OSX, and I'm trying to access an EC2 instance.
>

Shot in the dark here, but can you transfer anything to the host via a
manual sftp command line call (i.e. not using ansible) ? You may want
to check the machines /etc/ssh/sshd_config file to see if you have the
sftp subsystem configured correctly.

--
Romeo

nflacco

unread,
Nov 16, 2012, 10:38:25 PM11/16/12
to ansible...@googlegroups.com
You are correct!

Looks like default sftp info in the /etc/ssh/ssh_config file in CentOS is incorrect (http://blog.firsthand.ca/2009/01/cannot-connect-with-capistrano-or-sftp.html).

Replace in /etc/ssh/ssh_config:
# The default is incorrect
# Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp /usr/libexec/openssh/sftp-server
And restart sshd
sudo /etc/init.d/sshd restart
Reply all
Reply to author
Forward
0 new messages