hostvars behavior different version 1.9 ->2.1

24 views
Skip to first unread message

George Hunt

unread,
Sep 4, 2016, 12:52:10 AM9/4/16
to Ansible Project
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"

Kai Stian Olstad

unread,
Sep 4, 2016, 3:46:49 AM9/4/16
to ansible...@googlegroups.com
On 03. sep. 2016 21:49, George Hunt wrote:
> 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.


> 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"

--
Kai Stian Olstad

Reply all
Reply to author
Forward
0 new messages