1.4.4 accessing ansible_hostname from a template

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.

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