# hostvars behavior different version 1.9 -\>2.1

**URL:** <https://forum.ansible.com/t/hostvars-behavior-different-version-1-9-2-1/22477>\
**Category:** Ansible Project\
**Created:** [September 3, 2016, 7:49pm UTC](https://forum.ansible.com/t/hostvars-behavior-different-version-1-9-2-1/22477 "2016-09-03T19:49:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Hunt](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@George\_Hunt](https://forum.ansible.com/u/George_Hunt)\
**Post date:** [September 3, 2016, 7:49pm UTC](https://forum.ansible.com/t/hostvars-behavior-different-version-1-9-2-1/22477/1 "2016-09-03T19:49:48Z")

</div>

We have a template to create ifcfg files with the following partial snippet: (second line commented out for test with 2.1)

HWADDR={{ ansible\_wlp2s0.macaddress }}  
{#HWADDR={{ hostvars[inventory\_hostname][‘ansible\_’ + xsce\_wireless\_lan\_iface|trim][‘macaddress’] ]] #}

In ansible version 1.9 both HWADDR lines function. In version 2.1, I had to comment out the hostvars line to execute the template without error.

So the syntax has changed, or something. I tried setting gathering=implicit in ansible.conf, but it did not fix the problem

Does anyone have a new syntax that works in version 2.1

The error returned at the console was:

TASK [1-prep : WiFi enslaving wlp2s0 to Bridge] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute u’ansible\_wlp2s0’”}

yet indeed ansible\_wlp2s0 is defined when I do: “ansible -m setup localhost”

---

<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:** [September 4, 2016, 7:46am UTC](https://forum.ansible.com/t/hostvars-behavior-different-version-1-9-2-1/22477/2 "2016-09-04T07:46:18Z")

</div>

> We have a template to create ifcfg files with the following partial  
> snippet: (second line commented out for test with 2.1)
> 
> HWADDR={{ ansible\_wlp2s0.macaddress }}  
> {#HWADDR={{ hostvars[inventory\_hostname]['ansible\_' +  
> xsce\_wireless\_lan\_iface|trim]['macaddress'] ]] #}

You have two square brackets at the end where it should be two curly brackets.

> In ansible version 1.9 both HWADDR lines function. In version 2.1, I had to  
> comment out the hostvars line to execute the template without error.
> 
> So the syntax has changed, or something. I tried setting  
> gathering=implicit in ansible.conf, but it did not fix the problem
> 
> Does anyone have a new syntax that works in version 2.1

The syntax hasn't changed.
