Skip to content

Instantly share code, notes, and snippets.

@fbettag
Last active January 13, 2021 20:23
Show Gist options
  • Save fbettag/b69a6947ce00440ef5821ed241a086b3 to your computer and use it in GitHub Desktop.
Save fbettag/b69a6947ce00440ef5821ed241a086b3 to your computer and use it in GitHub Desktop.
AWK script which takes the output of "show configuration protocols bgp" on a Juniper Router and converts it into yaml. Can be used to convert an old configuration on a router into Ansible JunOS style. Should be adapter to your configuration style and case.
#!/usr/local/bin/gawk -f
/neighbor|peer-as|description|apply-group|authentication-key/ {
out="";
for (i=7; i<=NF; i++) {
out=out" "$i
}
gsub(/"/, "", out);
if ($6 == "neighbor") {
groups[$5][$6][length(groups[$5][$6])+1] = $7
} else {
groups[$5][$6] = out;
}
}
END {
for (key in groups) {
print " - group: "key;
print " peer_as:"groups[key]["peer-as"];
print " description:"groups[key]["description"];
print " apply_groups:"groups[key]["apply-groups"];
if ("authentication-key" in groups[key]) {
print " authentication_key:"groups[key]["authentication-key"];
}
print " neighbors:";
if (isarray(groups[key]["neighbor"])) {
for(i in groups[key]["neighbor"]) {
print " - "groups[key]["neighbor"][i]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment