# connection refused to "localhost" with paramiko

**URL:** <https://forum.ansible.com/t/connection-refused-to-localhost-with-paramiko/12610>\
**Category:** Ansible Project\
**Created:** [April 1, 2013, 1:10am UTC](https://forum.ansible.com/t/connection-refused-to-localhost-with-paramiko/12610 "2013-04-01T01:10:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [April 1, 2013, 1:10am UTC](https://forum.ansible.com/t/connection-refused-to-localhost-with-paramiko/12610/1 "2013-04-01T01:10:18Z")

</div>

I ran into a strange issue with the paramiko tranpsort today.

I launched a vagrant instance on my local machine (ssh port defaults to 2222). I created a hosts file that looks like this:

vagrant ansible\_ssh\_port=2222 ansible\_ssh\_host=localhost

My config file looks like this:

[defaults]  
hostfile = hosts  
remote\_user = vagrant  
private\_key\_file = /Users/lorin/.vagrant.d/insecure\_private\_key

If I try to connect to with paramiko, I get connection refused:

$ ansible vagrant -m ping  
vagrant | FAILED =\> FAILED: [Errno 61] Connection refused

Works fine with native ssh as the transport layer:

$ ansible vagrant -m ping -c ssh  
vagrant | success \>\> {  
“changed”: false,  
“ping”: “pong”  
}

It also works fine with paramiko if I change ansible\_ssh\_host to “127.0.0.1”, like so:

vagrant ansible\_ssh\_port=2222 ansible\_ssh\_host=127.0.0.1

$ ansible vagrant -m ping  
vagrant | success \>\> {  
“changed”: false,  
“ping”: “pong”  
}

Anyone know why paramiko succeeds on “127.0.0.1” but fails on “localhost” in this situation? I’m running off of the devel branch:

$ ansible --version  
ansible 1.1 (devel 304c447bd2) last updated 2013/03/31 16:57:58 (GMT -400)

I’m using paramiko 1.10.0.

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 1, 2013, 12:52pm UTC](https://forum.ansible.com/t/connection-refused-to-localhost-with-paramiko/12610/2 "2013-04-01T12:52:22Z")

</div>

I do not have that problem here, I'd assume it is an entirely  
legitimate connection failed message.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [April 1, 2013, 1:48pm UTC](https://forum.ansible.com/t/connection-refused-to-localhost-with-paramiko/12610/3 "2013-04-01T13:48:04Z")

</div>

I had similar issues and it had to do with an IPv6 localhost entry. Removing it resolved the issue (I wasn’t using IPv6 anyways).
