cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
768
Views
1
Helpful
3
Replies

Changing IP Address From DHCP to Static Using Onboarding Template in C

rawanmarnal69
Level 1
Level 1

hello,

we are using cisco dna to provision our branch switches without human touch. Switches succesfully obtain their IP addresses from DHCP server and appear on Cisco DNA and receive their configurations. For some security reasons we have to change int vlan 1 address from dhcp to static and for now we do it manually by configuring same ip address and gateway received from dhcp. I tried to automate this as well with using jinja template as below, but it did not help. Template system variables says __interface.ipv4Address exists but while doing configuration it fails. Jinja loop and condition works well as description is configured after onboarding.

3 Replies 3

Torbjørn
Spotlight
Spotlight

Could you post your jinja template? Do you wish to use the DHCP assigned address, or do you want to use another address in the end? 

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev

tsgruu2000
Level 1
Level 1

To just fix the address you could take something like this:

{% for interface in __interface %}
{% if '161' in interface.ipv4Address %}
{% set mgmt_vlan = interface.vlanId %}
vlan {{ mgmt_vlan }}
name Mgmt
!
ip route 0.0.0.0 0.0.0.0 {{ gateway }}
!
int vlan {{ mgmt_vlan }}
description Mgmt
ip address {{ interface.ipv4Address }} {{ interface.ipv4Mask }}
no ip dhcp client client-id

This works for me. Unfortunately, I can't find out how to read the default gateway obtained by DHCP with system variables and configure a default route from it  

Review Cisco Networking for a $25 gift card