I have to create a pipeline in order to automate creation-deployment and update configuration file for network devices (switch-routers-firewall, mostly cisco). There's many ways i think to do the job but i hesitate. The process would be to read a data file, search a string (example:hostname contains "NR") and if it's OK, choose the good template in a library in order to create the configuration file.
I've tried with ansible but things are not clear for me. The other way is jinja library and i've tried something like this
#! /usr/bin/python
import sys
from jinja2 import Template
template = """ hostname {{hostname}}
no ip domain lookup
ip domain name local.lab
ip name-server {{name_server_pri}}
ip name-server {{name_server_sec}}
ntp server {{ntp_server_pri}} prefer
ntp server {{ntp_server_sec}} """
data= {
"hostname": "core-test-01",
"name_server_pri": "1.1.1.1",
"name_server_sec": "8.8.8.8",
"ntp_server_pri": "0.pool.ntp.org",
"ntp_server_sec": "1.pool.ntp.org",
}
j2_template = Template(template)
print(j2_template.render(data))
In this case, how could i load a template file from a library (and in regarding of the string i want to find in my data file)?