# Ansible hostname alias not in setup

**URL:** <https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010>\
**Category:** Ansible Project\
**Created:** [April 14, 2014, 8:14am UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010 "2014-04-14T08:14:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [April 14, 2014, 8:14am UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/1 "2014-04-14T08:14:55Z")

</div>

```auto
Hi, having the following configuration

[my_hosts]
my_host ansible_ssh_host=123.123.123.123
my_host2 ansible_ssh_host=234.234.234.234

```

I want to gather some debug information in my templates.

- How do I acces the alias variable in a playbook/template? ie:`debug: `  
msg=Myhost is {{ ansible\_host\_alias }}
# Myhost is my\_host

# Myhost is myhost2
` `

I tried to gather facts using `ansible -m setup my_host` . The variables `ansible_hostname` , `HOSTNAME` and `HOST` contain the machine’s hostname, i.e. `echo $HOSTNAME` which differs from my ansible alias.

**- Is there really no such builtin variable?**

**- Would a feature request make sense, or should I better try to keep all my aliases in ssh\_config?**

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [April 15, 2014, 9:48am UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/2 "2014-04-15T09:48:43Z")

</div>

Try inventory\_hostname .

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [April 17, 2014, 1:33pm UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/3 "2014-04-17T13:33:05Z")

</div>

Thanks, that’s it. How did you find out? How do I find variables NOT defined in setup module?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [April 17, 2014, 1:39pm UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/4 "2014-04-17T13:39:28Z")

</div>

inventory\_hostname is a ‘magic’ variable and always present, its not part of fact gathering but inventory definition.

to see if a variable exists for a host you can do:

‘varname’ in hostvars[\<host’s inventory name\>]  
​

---

<div class="post-metadata">

**Author:** ![Tomasz\_Klosinski](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@Tomasz\_Klosinski](https://forum.ansible.com/u/Tomasz_Klosinski)\
**Post date:** [August 22, 2016, 8:43am UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/5 "2016-08-22T08:43:21Z")

</div>

Hello,

Is it possible to access {{ ansible\_ssh\_host }} variable from inventory in the above example? I need ip addresses to provision VMs before I run Ansible on them.  
Thanks in advance,

Tomasz Klosinski

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 22, 2016, 10:10am UTC](https://forum.ansible.com/t/ansible-hostname-alias-not-in-setup/15010/6 "2016-08-22T10:10:02Z")

</div>

Yes, but ansible\_ssh\_host is deprecated in version 2.x so use ansible\_host instead.
