Hello,
Here is the working script for You:
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
ns str = "http://exslt.org/strings";
import "../import/junos.xsl";
main <op-script-results> {
/* JUNOS XML API Element to retrieve the configuration */
var $config-rpc = <get-configuration database="committed" inherit="inherit"> {
<configuration> {
<protocols> {
<ospf>;
}
}
}
var $config = jcs:invoke($config-rpc);
var $ospf-config = $config/protocols/ospf/area;
var $ospf-ifl-list := {
for-each ($ospf-config[name == "0.0.0.0"]/interface[starts-with(name, "gr-")]) {
<interface> {
<name> ./name;
<passive>;
}
}
}
var $ospf-config2 := <configuration> {
<protocols> {
<ospf> {
<area> {
<name> "0.0.0.0";
copy-of $ospf-ifl-list;
}
}
}
}
var $connection = jcs:open();
var $results := {
call jcs:load-configuration($connection, $configuration = $ospf-config2);
}
if ($results//xnm:error) {
for-each ($results//xnm:error) {
<output> message;
}
}
}
General comments:
1/ use jcs:open() and jcs:execute() instead of jcs:invoke() - this is best practice
2/ do private commit with comment instead of default shared commit - again, this is best practice
3/ You missed quite a lot of XML tags to be wrapped around Your interface list
4/ consider what to do if all gr-* interfaces are already passive - You don't want to commit an empty config because it will eat up a slot in 50 recent commits limit that are kept by default.
5/ consider what to do if Your prepared interface list is empty - this can happen if someone removed gr-* interfaces from under [protocols ospf area 0], or removed [protocols ospf area 0], or removed [protocols ospf] - I hope You get my drift
HTH
Thx
Alex