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

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

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.

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