Template (filename port_vlan.j2):
interface vlan {{ vlan_name }}
ip address {{ ip }} {{ mask }}
exit
Python code to build configuration which adds an IP address to a VLAN…
python
import jinja2
import os
loader = jinja2.FileSystemLoader(os.getcwd())
loader
jenv = jinja2.Environment(loader=loader, trim_blocks=True, lstrip_blocks=True)
template = jenv.get_template(‘port_vlan.j2′)
template
print (template.render(vlan_name=10, ip=’10.10.10.1′, mask=’255.255.255.0’))
Output:
interface vlan 10
ip address 10.10.10.1 255.255.255.0
exit