# Creating a var from nested facts

**URL:** <https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469>\
**Category:** Ansible Project\
**Created:** [September 12, 2017, 10:46pm UTC](https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469 "2017-09-12T22:46:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 12, 2017, 10:46pm UTC](https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469/1 "2017-09-12T22:46:00Z")

</div>

I need to get the speed of the default ipv4 address; unfortunately, this information is contained within multiple facts.  
The default ipv4 address can be found in the “ansible\_default\_\_ipv4.interface” fact. The speed is then gathered from the “ansible\_.speed” fact.

I have tried a single variable and multiple variables to gather this info. I keep getting errors.

Am I approaching this right? Do I have a syntax issue?

vars:

`  
default\_eth: “{{ (ansible\_default\_ipv4.interface) }}”  
bitrate: “{{ (ansible.{{ default\_eth }}.speed)|int|abs }}”

`

Also tried:

`  
bitrate: “{{ (ansible.{{ansible\_default\_ipv4.interface}}.speed)|int|abs }}”

`

Sample Failure:

`  
fatal: [ansibletest-oel6]: FAILED! =\> {“failed”: true, “msg”: “{{ (ansible.{{default\_eth}}.speed)|int|abs }}: template error while templating string: expected name or number. String: {{ (ansible.{{default\_eth}}.speed)|int|abs }}”}

`

---

<div class="post-metadata">

**Author:** ![Nils\_Steinger](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@Nils\_Steinger](https://forum.ansible.com/u/Nils_Steinger)\
**Post date:** [September 12, 2017, 11:17pm UTC](https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469/2 "2017-09-12T23:17:30Z")

</div>

- hosts: all  
&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug: 'msg="{{vars[\"ansible\_\" +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible\_default\_ipv4.interface].speed}}"'

(based partially on [https://stackoverflow.com/a/33444051/1114687](https://stackoverflow.com/a/33444051/1114687))

But really, we should just provide the interface information as a  
dictionary, as we're already doing with disk devices…

Regards,  
Nils

---

<div class="post-metadata">

**Author:** ![Nils\_Steinger](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@Nils\_Steinger](https://forum.ansible.com/u/Nils_Steinger)\
**Post date:** [September 12, 2017, 11:39pm UTC](https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469/3 "2017-09-12T23:39:45Z")

</div>

I've opened an issue about this, if anyone wants to chime in:  
[https://github.com/ansible/ansible/issues/30246](https://github.com/ansible/ansible/issues/30246)

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [September 13, 2017, 2:55pm UTC](https://forum.ansible.com/t/creating-a-var-from-nested-facts/25469/4 "2017-09-13T14:55:23Z")

</div>

Awesome, thanks!
