# \`ansible\_host\` with \`delegate\_to\` points to \`inventory\_hostname\`, not delegated host

**URL:** <https://forum.ansible.com/t/ansible-host-with-delegate-to-points-to-inventory-hostname-not-delegated-host/45075>\
**Category:** Get Help\
**Tags:** template, ansible-core\
**Created:** [January 9, 2026, 11:29am UTC](https://forum.ansible.com/t/ansible-host-with-delegate-to-points-to-inventory-hostname-not-delegated-host/45075 "2026-01-09T11:29:18Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![marvic](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@marvic](https://forum.ansible.com/u/marvic)\
**Post date:** [January 9, 2026, 4:40pm UTC](https://forum.ansible.com/t/ansible-host-with-delegate-to-points-to-inventory-hostname-not-delegated-host/45075/4 "2026-01-09T16:40:58Z")

</div>

Actually the situation with connection variables like `ansible_host`, `ansible_connection` etc. in combination with `delegate_to: D` is a bit more nuanced. Let’s take `ansible_host` as example:

- `ansible_host` from `D` is always used to establish a connection.
- For templating, if `inventory_hostname` has `ansible_host` explicitely declared (e.g. via host\_vars), then `ansible_host` is used from here.
- Otherwise `ansible_host` is taken from `D`.
- Other variable types are not taken at all from `D`.

That leads to the curiosity, that when resolving `ansible_host` via DNS, my playbook works, but when declaring `ansible_host` explicitely in host\_vars, it fails.

As connection variables are already handled in a specialized way for `delegate_to` directive and are always taken from delegated host context for connection establishment, why not adhere to same principles the other way round and always return delegate host values for `ansible_host` & Co. during template interpolation?

Is this purely based on historical decisions? I might be missing something - please correct me otherwise, but from bare user perspective current design chocie seems to be the most inconsistent and least intuitive.

See also [Variables not consumed from delegated host - #3 by kristianheljas](https://forum.ansible.com/t/variables-not-consumed-from-delegated-host/40621/3) .

---

_[View the full topic](https://forum.ansible.com/t/ansible-host-with-delegate-to-points-to-inventory-hostname-not-delegated-host/45075)._
