# Jinja2 - snmp\_facts - dynamic template genration

**URL:** <https://forum.ansible.com/t/jinja2-snmp-facts-dynamic-template-genration/21412>\
**Category:** Ansible Project\
**Created:** [May 11, 2016, 3:50pm UTC](https://forum.ansible.com/t/jinja2-snmp-facts-dynamic-template-genration/21412 "2016-05-11T15:50:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michal\_trembacz](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@michal\_trembacz](https://forum.ansible.com/u/michal_trembacz)\
**Post date:** [May 11, 2016, 3:50pm UTC](https://forum.ansible.com/t/jinja2-snmp-facts-dynamic-template-genration/21412/1 "2016-05-11T15:50:47Z")

</div>

Hi,

I’m trying to use snmp\_facts module to retrieve information from Cisco IOS device.  
I want to use this information to generate config.  
Module works ok, but it returns strange list format that from which i can’t access values from within j2 template.

The issue I have is the format of list after “ipv4”.  
Example snmp\_facts output:

ok: [csr-test] =\>  
{“ansible\_facts”:  
{“ansible\_all\_ipv4\_addresses”: [“10.50.0.103”, “192.168.103.254”],  
“ansible\_interfaces”:  
{“1”: {“adminstatus”: “down”, “description”: “”, “ifindex”: “1”, “mac”: “000c29f30bdd”, “mtu”: “1500”, “name”: “GigabitEthernet1”, “operstatus”: “down”, “speed”: “1500”},  
“2”: {“adminstatus”: “up”, “description”: “”, “ifindex”: “2”, “ipv4”: [{“address”: “10.50.0.103”, “netmask”: “255.255.255.0”}], “mac”: “000c29f30be7”, “mtu”: “1500”, “name”: “GigabitEthernet2”, “operstatus”: “up”, “speed”: “1500”},  
“3”: {“adminstatus”: “up”, “description”: “”, “ifindex”: “3”, “ipv4”: [{“address”: “192.168.103.254”, “netmask”: “255.255.255.0”}], “mac”: “000c29f30bf1”, “mtu”: “1500”, “name”: “GigabitEthernet3”, “operstatus”: “up”, “speed”: “1500”},  
“4”: {“adminstatus”: “up”, “description”: “”, “ifindex”: “4”, “mac”: “”, “mtu”: “1500”, “name”: “VoIP-Null0”, “operstatus”: “up”, “speed”: “1500”}, “5”: {“adminstatus”: “up”, “description”: “”, “ifindex”: “5”, “mac”: “”, “mtu”: “1500”, “name”: “Null0”, “operstatus”: “up”, “speed”: “1500”}},  
“ansible\_syscontact”: “”,  
“ansible\_sysdescr”: "Cisco IOS Software, CSR1000V ",  
“ansible\_syslocation”: “”,  
“ansible\_sysname”: “CSR1000V-01”, “ansible\_sysobjectid”: “1.3.6.1.4.1.9.1.1537”,  
“ansible\_sysuptime”: “240793753”},

From output above i can get interface name via

{% set interface\_name = hostvars[inventory\_hostname].ansible\_interfaces[interface\_no][‘name’] %}

But if i try using

{%hostvars[inventory\_hostname].ansible\_interfaces[interface\_no][‘name’]['ipv4][‘address’] %}

it returns that there is no such a attribute.

I’m using Ansible 2.2 and Jinja 2.8

Could you please point me at some direction ?

Michal
