Template Editor - jinja2 ipaddr filter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2022 11:09 AM
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!
- Labels:
-
Cisco DNA Automation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2022 12:42 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 06:23 AM
Thanks @Preston Chilcote I have submitted a Make a Wish from both our Lab and our Production instance
Looking forward to future updates for this product.
