12-17-2018 12:07 PM
Hi experts!!
Is it possible to create a device template with variables and apply it so the template variables are self populated from certain data of device model (xpath to device model)?
For example, we have a snmp template that sets the read community value to the device hostname value, is this doable using device templates and applying it to the bulk of devices?
Could you please share an example of it?
thanks a lot in advance
regards
Rob
Solved! Go to Solution.
12-18-2018 06:09 AM
I agree with Victor. This is certainly possible, and I have done it occasionally. The thing is that these XPath expressions quickly get quite complex, and you either need to get hold of a real XPath expert, or become one yourself. Your time is probably better invested in writing a simple template based service instead.
12-17-2018 12:56 PM
It is possible, but perhaps that is the kind of situation where you want to consider a service. Also, since this is not properly documented I am not entirely sure how supported it is. But, you do have access to a variable $DEVICE that points to the current device, thus you can do something like this:
admin@ncs% show devices device jun0 config junos:configuration interfaces interface description interface xe-0/0/0 { description Test; } interface xe-0/0/1 { description A; } interface xe-0/0/2 { description Good; } [ok][2018-11-30 12:05:09] [edit] admin@ncs% show devices template template templ1 { config { junos:configuration { interfaces { interface "{/devices/device[name=$DEVICE]/config/junos:configuration/interfaces/interface[description='A']/name}" { hold-time { up 30; down 30; } } } } } } [ok][2018-11-30 12:05:12] [edit] admin@ncs% request devices device jun0 apply-template template-name templ1 apply-template-result { device jun0 result ok } [ok][2018-11-30 12:05:22] [edit] admin@ncs% commit dry-run cli { local-node { data devices { device jun0 { config { junos:configuration { interfaces { interface xe-0/0/1 { + hold-time { + up 30; + down 30; + } } } } } } } } } [ok][2018-11-30 12:05:25]
(This examples sets parameters for all interfaces that have the description 'A')
12-18-2018 06:09 AM
I agree with Victor. This is certainly possible, and I have done it occasionally. The thing is that these XPath expressions quickly get quite complex, and you either need to get hold of a real XPath expert, or become one yourself. Your time is probably better invested in writing a simple template based service instead.
12-18-2018 06:23 AM
Thanks a lot Viktor
I was looking for a solution oriented to compliance reports where the templates have variables and devices have different variable values. I was willing to create a bulk compliance report (for devices with different variable values) doing either:
1) Fulling the variable value from each device mode data (running config)
2) Defining arrays of variables that match with the device grouping order
is any of this possible?
thanks a lot
regards
Rob
12-18-2018 06:43 AM
Totally agree, I gave it a go with a small example and compliance report works
devices template SNMP-OSP
config
vrp:snmp-agent community cipher-name-replace {/devices/device[name=$DEVICE]/config/vrp:sysname}
!
Not sure if we can define the variable generic and define an array of values too
device-group [r1 r2 ... rn]
variable [v1 v2 ... vn]
thanks a lot
Helpful indeed
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide