# connection=autolocal

**URL:** <https://forum.ansible.com/t/connection-autolocal/14881>\
**Category:** Ansible Project\
**Created:** [March 28, 2014, 10:49am UTC](https://forum.ansible.com/t/connection-autolocal/14881 "2014-03-28T10:49:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [March 28, 2014, 10:49am UTC](https://forum.ansible.com/t/connection-autolocal/14881/1 "2014-03-28T10:49:10Z")

</div>

Is it possible to define host in inventory in a way that will use local connection is the name resolves to local address?

Is it worth to add connection=autolocal option?

---

<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:** [March 28, 2014, 1:37pm UTC](https://forum.ansible.com/t/connection-autolocal/14881/2 "2014-03-28T13:37:44Z")

</div>

We would not be taking a pull request for a new connection option.

However, if you want to make sure the localhost if in the host file is always local:

localhost ansible\_connection=local

(_Further_, Ansible now has “implicit localhost” capabilities so localhost doesn’t have to be in inventory in most cases, and if not there and referenced, it is assumed to be a local connection)

---

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [March 29, 2014, 5:49am UTC](https://forum.ansible.com/t/connection-autolocal/14881/3 "2014-03-29T05:49:05Z")

</div>

No. I want to make connection to host "yetanothernode" local only if I execute  
playbook on this host itself. If I execute playbook for this host from other  
machine, I want it to connect to "yetanothernode" by SSH as usual.

The problem can also be generalized for nodes inside subnetwork, where  
node see each other by local IPs (or local protocol) and should connect  
using custom connection if some condition is met. If condition is not met,  
we assume to be outside the network and fall down to standard connection  
type.

---

<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:** [March 30, 2014, 10:18pm UTC](https://forum.ansible.com/t/connection-autolocal/14881/4 "2014-03-30T22:18:24Z")

</div>

Hmmm, this would require some games to figure out if the hostname in the playbook matched what the local machine was saying it was.

I’m inclined to say no to this, and it can be greatly simplified by even allowing the machine to be managed locally over SSH if you want - - if localhost is not special.

Generally most people are designing a node for management purposes rather than running Ansible from one of the nodes in a cluster, etc, so I can’t see this being a very common use case.

Perhaps I’m misunderstanding though.
