# 1.4.4 accessing ansible\_hostname from a template

**URL:** <https://forum.ansible.com/t/1-4-4-accessing-ansible-hostname-from-a-template/14438>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 27, 2014, 10:01pm UTC](https://forum.ansible.com/t/1-4-4-accessing-ansible-hostname-from-a-template/14438 "2014-01-27T22:01:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Zarecor](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Ed\_Zarecor](https://forum.ansible.com/u/Ed_Zarecor)\
**Post date:** [January 27, 2014, 10:01pm UTC](https://forum.ansible.com/t/1-4-4-accessing-ansible-hostname-from-a-template/14438/1 "2014-01-27T22:01:55Z")

</div>

We’ve recently upgraded to 1.4.

In 1.3 this worked fine in a template

host = {{ansible\_hostname}}

In 1.4.4

I’m seeing this

fatal: [localhost] =\> {‘msg’: “One or more undefined variables: ‘ansible\_hostname’ is undefined”, ‘failed’: True}

Running

ubuntu@ip-10-0-x-x:~$ ansible -i inventory.ini localhost -m setup -c local | grep ansible\_host

returns

“ansible\_hostname”: “ip-10-0-200-247”,

Has something changed or are we using the wrong approach here?

Best,

Ed.

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [January 27, 2014, 10:44pm UTC](https://forum.ansible.com/t/1-4-4-accessing-ansible-hostname-from-a-template/14438/2 "2014-01-27T22:44:04Z")

</div>

Since ansible\_hostname is a fact that comes out of setup, are you positive that gather\_facts: is happening in your playbook?

You are dealing with localhost it seems, and with 1.4 there is some new magic around localhost and inventories, which may lead to setup not exactly running there.

Is localhost explicitly in your inventory?

-jlk
