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 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e6cc6a47-584e-46df-81e7-06bc2a2180f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to