cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1308
Views
0
Helpful
2
Replies

Template Editor - jinja2 ipaddr filter

Doug Byrd
Level 5
Level 5

I'm working with some Jinja2 templates and have a need to use Jinja2's 'ipaddr' filter.  Since this isn't well documented from a DNAC perspective, I've been trying to use some of the attributes/schema that are present in the Ansible version of ipaddr.  I've got the basics working, but I seem to be getting stuck on the syntax for choosing an index/ipaddress in a network.

 

I have this working properly:

{% set network = '192.168.2.5/22' %}

Input: {{ network }}
Network Address: {{ network | ipaddr('network') }}
Address: {{ network | ipaddr('address') }}
Netmask: {{ network | ipaddr('netmask') }}
Prefix: {{ network | ipaddr('prefix') }}
Broadcast: {{ network | ipaddr('broadcast') }}
Input: 192.168.2.5/22
Network Address: 192.168.0.0
Address: 192.168.2.5
Netmask: 255.255.252.0
Prefix: 22
Broadcast: 192.168.3.255

What I want to be able to do is address an IP address by it's index.  For example, in Ansible I can programmatically choose the gateway to be the first usable ip address in a network by using something like:

{% set network = "192.168.1.0/24" %}
HSRP IP: {{ network | ipaddr(1) | ipaddr('address') }}
Router 1: {{ network | ipaddr(2) | ipaddr('address') }}
Router 2: {{ network | ipaddr(3) | ipaddr('address') }}
LB VIP: {{ network | ipaddr(-2) | ipaddr('address') }}
LB1: {{ network | ipaddr(-3) | ipaddr('address') }}
LB2: {{ network | ipaddr(-4) | ipaddr('address') }}
HSRP IP: 192.168.1.1
Router 1: 192.168.1.2
Router 3: 192.168.1.3
LB VIP: 192.168.1.254
LB1: 192.168.1.253
LB2: 192.168.1.252

Am I just missing the proper syntax, or is this functionality even available?

 

Thanks!

2 Replies 2

Preston Chilcote
Cisco Employee
Cisco Employee

In principle, the Cisco DNA jinja editor should allow copy/paste from your Ansible jinja templates.  Please submit a Make a Wish via the GUI's help menu to let the development team know of this missing feature.  

Thanks @Preston Chilcote I have submitted a Make a Wish from both our Lab and our Production instance    No one has yet to reach out, so I posted here to see if anyone had worked through it already.

 

Looking forward to future updates for this product.