# What determines the value of inventory\_hostname

**URL:** <https://forum.ansible.com/t/what-determines-the-value-of-inventory-hostname/24736>\
**Category:** Ansible Project\
**Created:** [June 15, 2017, 3:51pm UTC](https://forum.ansible.com/t/what-determines-the-value-of-inventory-hostname/24736 "2017-06-15T15:51:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Stanfield](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Richard\_Stanfield](https://forum.ansible.com/u/Richard_Stanfield)\
**Post date:** [June 15, 2017, 3:51pm UTC](https://forum.ansible.com/t/what-determines-the-value-of-inventory-hostname/24736/1 "2017-06-15T15:51:59Z")

</div>

I’m very new to Ansible and I have inherited some Ansible playbooks that aren’t working that I need to get working. I’ve been searching for quite some time and haven’t found any answers for this.

My current problem is that inventory\_hostname is being set to localhost and I need confirmation on why. These playbooks are being used to setup the Ansible master server, and I am only running them locally.

The hostname of this machine is ansiblemaster.

I’ve created two small playbooks that reproduce the behavior I am seeing. The first one, is this

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 15, 2017, 7:58pm UTC](https://forum.ansible.com/t/what-determines-the-value-of-inventory-hostname/24736/2 "2017-06-15T19:58:54Z")

</div>

so lets see if this explains it:

hosts: \<host pattern\> reffers to groups/hostnames defined in your  
inventory, Ansible always provides a definition for 'localhost' just  
in case it is needed.

`inventory_hostname` is 'the name you defined in inventory', the  
hostname of the machine will appear in gathered facts (several  
depending on config/OS/etc) ansible\_nodename, asnible\_fqdn, etc. This  
is not the same as hosts: , though both rely on the inventory data.

ansible\_host is the variable that contains the 'actual info used to  
connect to the host', which you can set in inventory or ansible will  
set at each task when needed (ansible\_ssh\_host or ansible\_winrm\_host  
for specific connection plugins).

None of these set the hostname for your machine (you need to use the  
hostname module for that), they are just aliases/ways to refer to that  
machine.
