# Get host name from inventory on remote host?

**URL:** <https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486>\
**Category:** Ansible Project\
**Created:** [May 2, 2012, 3:01am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486 "2012-05-02T03:01:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanosh](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@seanosh](https://forum.ansible.com/u/seanosh)\
**Post date:** [May 2, 2012, 3:01am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486/1 "2012-05-02T03:01:31Z")

</div>

Was wondering if there's a way to get the hostname I've specified in  
my inventory available as a var for use in a template on the remote  
host? Would be useful for setting the hostname properly of a new  
server that may have a different hostname defined in the setup  
ansible\_fqdn or ansible\_hostname data... similar to the way  
group\_names are exposed in the setup data - maybe an  
inventory\_hostname?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 2, 2012, 3:40am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486/2 "2012-05-02T03:40:25Z")

</div>

We were discussing this on IRC today in fact, not presently, but it's going to be added.

I like inventory\_hostname as a suggested name pretty well. I think we were thinking in terms of ansible\_connectedname  
though inventory\_hostname makes better sense.

--Michael

---

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [May 2, 2012, 3:46am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486/3 "2012-05-02T03:46:25Z")

</div>

+1 inventory\_hostname

-sv

---

<div class="post-metadata">

**Author:** ![seanosh](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@seanosh](https://forum.ansible.com/u/seanosh)\
**Post date:** [May 2, 2012, 4:23am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486/4 "2012-05-02T04:23:58Z")

</div>

(realized I replied to author instead of reply)...

That's great news - will keep an eye out for it. Would consider  
providing a patch but could use some brushing up on my Python  
first...

Loving Ansible so far - coming from Puppet, this is much simpler and  
just what I need... keep it up!

---

<div class="post-metadata">

**Author:** ![Jeroen\_Hoekx](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@Jeroen\_Hoekx](https://forum.ansible.com/u/Jeroen_Hoekx)\
**Post date:** [May 2, 2012, 7:56am UTC](https://forum.ansible.com/t/get-host-name-from-inventory-on-remote-host/11486/5 "2012-05-02T07:56:18Z")

</div>

Good idea. I was using a hostname variable in my playbooks.

I'll take this one (it's a 3 line patch or so)!

Jeroen
