# Problem setting variable with bond0.11 IPv4 address from the gathered facts.

**URL:** <https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691>\
**Category:** Ansible Project\
**Created:** [November 4, 2014, 7:51pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691 "2014-11-04T19:51:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Sdc](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joel\_Sdc](https://forum.ansible.com/u/Joel_Sdc)\
**Post date:** [November 4, 2014, 7:51pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/1 "2014-11-04T19:51:08Z")

</div>

Hi,

I am using Ansible v1.7.1.

I am having trouble using the gathered facts when an interface has bonding and VLANs enabled:

# ansible -m setup testserver

[…]

“ansible\_bond0.11”: {  
“active”: true,  
“device”: “bond0.11”,  
“ipv4”: {  
“address”: “192.168.11.66”,  
“netmask”: “255.255.255.0”,  
“network”: “192.168.11.0”  
},  
“macaddress”: “d4:ae:52:98:71:1f”,  
“mtu”: 1500,  
“promisc”: false,  
“type”: “ether”  
},

[…]

Then, I have a playbook that sets a variable:

Example from a different server that doesn’t have bonding or VLANs:

listen\_ip: “{{ ansible\_eth1.ipv4.address }}”

Example that doesn’t work:

listen\_ip: “{{ ansible\_bond0.11.ipv4.address }}”

Ansible output:

fatal: [testserver] =\> {‘msg’: ‘AnsibleUndefinedVariable: One or more undefined variables: dict object has no element 11’, ‘failed’: True}  
fatal: [testserver] =\> {‘msg’: ‘AnsibleUndefinedVariable: One or more undefined variables: dict object has no element 11’, ‘failed’: True}

FATAL: all hosts have already failed – aborting

I have tried different possibilities but they all failed:

“{{ ansible\_bond0.11.ipv4.address }}”

“{{ ansible\_bond0\.11.ipv4.address }}”

“{{ [ansible\_bond0.11].ipv4.address }}”

“{{ {ansible\_bond0.11}.ipv4.address }}”

“{{ ‘ansible\_bond0.11’.ipv4.address }}”

I think Ansible is taking the VLAN tag as part of the subgroup in the config…

What is the correct way of selecting the IPv4 address of a bond0.11 interface?

Thank you in advanced.

Best regards,  
J.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 4, 2014, 8:21pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/2 "2014-11-04T20:21:39Z")

</div>

To use a hostvar that contains a ‘.’ you will need to do something such as:

{{ hostvars[inventory\_hostname][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}

---

<div class="post-metadata">

**Author:** ![Joel\_Sdc](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joel\_Sdc](https://forum.ansible.com/u/Joel_Sdc)\
**Post date:** [November 4, 2014, 10:25pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/3 "2014-11-04T22:25:59Z")

</div>

Hi Matt,

Would this be valid?

"{{ hostvars[{{ ansible\_host }}]['ansible\_bond0.11']['ipv4']['address'] }}"

This is the playbook:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 5, 2014, 2:14pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/4 "2014-11-05T14:14:17Z")

</div>

> > “{{ hostvars[{{ ansible\_host }}][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}”

You’ll want to remove the template stuff inside the template stuff:

“{{ hostvars[ansible\_host][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}”

---

<div class="post-metadata">

**Author:** ![Joel\_Sdc](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joel\_Sdc](https://forum.ansible.com/u/Joel_Sdc)\
**Post date:** [November 5, 2014, 10:06pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/5 "2014-11-05T22:06:12Z")

</div>

Hi Michael,

Just tried, same problem…

“{{ hostvars[ansible\_host][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}”:

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

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

FATAL: all hosts have already failed – aborting

Just in case, tried this one also:

“{{ hostvars[‘ansible\_host’][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}”

fatal: [testserver1] =\> {‘msg’: ‘AnsibleError: host not found: ansible\_host’, ‘failed’: True}  
fatal: [testserver1] =\> {‘msg’: ‘AnsibleError: host not found: ansible\_host’, ‘failed’: True}

fatal: [testserver2] =\> {‘msg’: ‘AnsibleError: host not found: ansible\_host’, ‘failed’: True}  
fatal: [testserver2] =\> {‘msg’: ‘AnsibleError: host not found: ansible\_host’, ‘failed’: True}

FATAL: all hosts have already failed – aborting

Any other ideas?

Thank you!

J.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 5, 2014, 10:12pm UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/6 "2014-11-05T22:12:06Z")

</div>

According to that error, you have not defined a variable called ‘ansible\_host’. Where is that variable supposed to be coming from?

The variable that ansible creates that references the current host is called inventory\_hostname. Perhaps you were meaning ansible\_hostname?

In either case inventory\_hostname is safer to use, as that is what ansible knows about from the inventory, and ansible\_hostname is not necessarily the same value as inventory\_hostname.

---

<div class="post-metadata">

**Author:** ![Joel\_Sdc](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joel\_Sdc](https://forum.ansible.com/u/Joel_Sdc)\
**Post date:** [November 11, 2014, 11:23am UTC](https://forum.ansible.com/t/problem-setting-variable-with-bond0-11-ipv4-address-from-the-gathered-facts/16691/7 "2014-11-11T11:23:38Z")

</div>

Hi Matt,

I just wanted to say that it worked perfectly as you said.

The correct format is:

“{{ hostvars[inventory\_hostname][‘ansible\_bond0.11’][‘ipv4’][‘address’] }}”

Thank you very much.  
J.
