# FAILED =\> SSH Error: ssh: connect to host 127.0.0.1 port 2222: connection refused

**URL:** <https://forum.ansible.com/t/failed-ssh-error-ssh-connect-to-host-127-0-0-1-port-2222-connection-refused/18300>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 25, 2015, 11:00am UTC](https://forum.ansible.com/t/failed-ssh-error-ssh-connect-to-host-127-0-0-1-port-2222-connection-refused/18300 "2015-05-25T11:00:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vamsee\_krishna](https://avatars.discourse-cdn.com/v4/letter/v/cc9497/32.png) [@vamsee\_krishna](https://forum.ansible.com/u/vamsee_krishna)\
**Post date:** [May 25, 2015, 11:00am UTC](https://forum.ansible.com/t/failed-ssh-error-ssh-connect-to-host-127-0-0-1-port-2222-connection-refused/18300/1 "2015-05-25T11:00:41Z")

</div>

Hi All,

I’m new to Ansible. started working on Ansible basics.

I installed Ubuntu 14.04 in virtual box and installed Ansible using the following commands

```auto
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

```

```auto
from Ansible documentation

```

```auto
Later I updated the hosts file in /etc/ansible to

```

```auto
[webservers]

```

```auto
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222

```

```auto
and tried to ping using the command 

```

```auto
ansible webservers -m ping and I'm getting an error message 

```

```auto
testserver | FAILED => SSH Error: ssh: connect to host 127.0.0.1 port 2222: Connection refused while connecting to [127.0.0.1:2222](http://127.0.0.1:2222/)

```

It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

When I googled for connection refused type issues I thought that I should be installing Open SSH server in Ubuntu and did the same using the command

sudo apt-get install openssh-server

Even then I’m getting the same error.

Please let me know if i did some thing wrong or provide any links that i could follow to solve the above issue

---

<div class="post-metadata">

**Author:** ![Gerard\_Lynch](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@Gerard\_Lynch](https://forum.ansible.com/u/Gerard_Lynch)\
**Post date:** [May 26, 2015, 9:53am UTC](https://forum.ansible.com/t/failed-ssh-error-ssh-connect-to-host-127-0-0-1-port-2222-connection-refused/18300/2 "2015-05-26T09:53:13Z")

</div>

It’s not clear whether you 1) installed Ansible inside the virtual machine, or 2) locally.

1. 

If you installed it inside your virtual machine, and want to test against the localhost, then your /etc/ansible/hosts file can just be

`  
[webservers]  
testserver ansible\_connection=local

`

1. 

If you’ve installed ansible locally, and wish to test it against your virtual machine, then the settings you’ve used (ansible\_ssh\_host=127.0.0.1 ansible\_ssh\_port=2222) would be valid if you’re running your instance using Vagrant. As a default vagrant instance listens on 127.0.0.1:2222 (it performs port forwarding from 2222-\>22). If you’re using Vagrant then obviously you’ll need to do a ‘vagrant up’ to start the instance otherwise it won’t be able to connect.

If you’re using something other than Vagrant, e.g. just plain VirtualBox, then you’ll need to setup networking so that you can communicate between your local machine and the instance, and then you’ll need to update the inventory to use the correct address/port details.

Also, OpenSSH is installed by default on most Linux servers.

Hope that helps
