# 127.0.0.1 and localhost in synchronize module

**URL:** <https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726>\
**Category:** Ansible Project\
**Created:** [July 21, 2014, 6:38pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726 "2014-07-21T18:38:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Dur](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Michael\_Dur](https://forum.ansible.com/u/Michael_Dur)\
**Post date:** [July 21, 2014, 6:38pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/1 "2014-07-21T18:38:47Z")

</div>

Why is localhost and 127.0.0.1 a special case in the synchronize module?

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [July 21, 2014, 10:43pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/2 "2014-07-21T22:43:27Z")

</div>

Given the nature of rsync and what it does, your question can be read a few ways but let me guess at what you are getting at.

127.0.0.1 and localhost are treated specially because you're already on that box so you don't need to provide all of the SSH credentials. You can do a sync that doesn't go out to the network at all.

\<tim/\>

---

<div class="post-metadata">

**Author:** ![Jeppe\_Toustrup](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@Jeppe\_Toustrup](https://forum.ansible.com/u/Jeppe_Toustrup)\
**Post date:** [August 13, 2014, 2:59pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/3 "2014-08-13T14:59:52Z")

</div>

Sorry for bringing up a (somewhat) old topic, but what about the use case where Ansible is used to configure a Vagrant VM? In that case the VM would be accessible through 127.0.0.1:2222, and thus get hit by the special handling in the synchronization module. This means if you want to write to a path where the unprivileged/‘vagrant’ user doesn’t have write permissions, you will have to add the non-obvious ‘rsync\_path=“sudo rsync”’ to your task configuration, instead of just adding ‘sudo: True’ like everywhere else in order to get the same result.

I don’t know if there’s a good way to detect situations like this so ‘sudo: True’ can have the proper effect. If not, then I think it might be worth mentioning explicitly in the documentation for the module.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 14, 2014, 11:41am UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/4 "2014-08-14T11:41:31Z")

</div>

Ansible views Vagrant as no different than any other computer.

I believe it should set ansible\_ssh\_port in inventory.

If you can paste what kind of errors you are seeing and your ansible version it might be more clear what you’re talking about, but I don’t understand “get hit by the special handling” means in this particular case exactly.

More information would be useful.

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 3, 2015, 6:13pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/5 "2015-01-03T18:13:09Z")

</div>

Here’s what I do to gain some other benefits:

- I let Vagrant dynamically generate the hosts file that is later used by Ansible.- the Vagrant boxes use a different subnet thus not conflicting with the corner case described above.

---

<div class="post-metadata">

**Author:** ![Leonel\_Galan\_Recinos](https://avatars.discourse-cdn.com/v4/letter/l/d2c977/32.png) [@Leonel\_Galan\_Recinos](https://forum.ansible.com/u/Leonel_Galan_Recinos)\
**Post date:** [February 4, 2015, 9:35pm UTC](https://forum.ansible.com/t/127-0-0-1-and-localhost-in-synchronize-module/15726/6 "2015-02-04T21:35:02Z")

</div>

Dan, this is far from a corner case. Vagrant’s default behavior is to setup the ssh address to: 127.0.0.1:2222.

Michael, thanks for your hard work on Ansible! It’s not that it treats Vagrant boxes differently, _synchronize_ treats localhost and 127.0.0.1 differently, but maybe it shouldn’t unless `ansible_connection=local` is set. I posted extended logs and information on my inventory file and task in [https://github.com/ansible/ansible/issues/5240#issuecomment-72944174](https://github.com/ansible/ansible/issues/5240#issuecomment-72944174)
