Junos Annotate Example

The Junos ‘annotate’ command is a handy way of placing comments into the configuration file. I haven’t seen it widely used in production networks. In non-production environments, it’s a helpful way to identify what project or which engineer has put test config onto the lab equipment.

For example, if I’m testing some new feature or functionality in the lab I can comment the relevant portions of the config. This allows people to contact me if the config causes issues and needs to be removed or deactivated.

Annotations also lead to the fun pastime of spotting lab configuration in the production network when someone forgets to remove the comments.

Examples

Adding Annotations

We can add comments to the configuration with the annotate command as follows:

annotate <config statement> “Comment between quotation marks”

In the following example, we will annotate two interfaces. This is a little redundant since we could simply set a description, but it shows the basic idea. It is much more useful in areas of the config that don’t have the option to set a description.

[edit interfaces]
lab@vMX-1# show 
ge-0/0/1 {
    unit 0;
}
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# annotate ge-0/0/1 "My First Comment"                            

[edit interfaces]
lab@vMX-1# annotate ge-0/0/2 "#My Second Comment Uses A Hash Character"    

[edit interfaces]
lab@vMX-1# show 
/* My First Comment */
ge-0/0/1 {
    unit 0;
}
#My Second Comment Uses A Hash Character
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# show | compare 
[edit interfaces]
+  /* My First Comment */
   ge-0/0/1 { ... }
[edit interfaces]
+  #My Second Comment Uses A Hash Character
   ge-0/0/2 { ... }

[edit interfaces]
lab@vMX-1# commit 
commit complete

[edit interfaces]
lab@vMX-1#

There are a few things you should notice about the above:

  • If the comment is more than one word, it should be enclosed in quotation marks
  • The comment appears before the config statement that was referenced
  • If you use a hash (#) character at the start of your comment, then the comment starts with ‘#’ instead of ‘/*’ and ending in ‘*/’
  • A commit is still needed after the annotation is made

Removing Annotations

Think about Junos for a moment – how do you think an annotation is removed? If we want to remove a ‘set’ statement, we ‘delete’ it. If we ‘deactivate’ a piece of config, we ‘activate’ it to make it active again.

Obviously, if we ‘annotate’ a config statement, there should be some sort of ‘deannotate’ or ‘annotate delete’ command right? Well, no, that would make too much sense. 

To remove an annotation, you replace it by setting a blank annotation.

annotate <config statement> “”

Let’s remove the comment from interface ge-0/0/1.

[edit interfaces]
lab@vMX-1# show 
/* My First Comment */
ge-0/0/1 {
    unit 0;
}
#My Second Comment Uses A Hash Character
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# annotate ge-0/0/1 ""                                            

[edit interfaces]
lab@vMX-1# show 
ge-0/0/1 {
    unit 0;
}
#My Second Comment Uses A Hash Character
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# show | compare 
[edit interfaces]
-  /* My First Comment */
   ge-0/0/1 { ... }

[edit interfaces]
lab@vMX-1# commit 
commit complete

[edit interfaces]
lab@vMX-1#

There is also the burn-it-to-the-ground approach you might see taken by someone unfamiliar with annotation. With this approach, you delete the commented config statement and then re-add it again. Not a practice I would recommend.

[edit interfaces]
lab@vMX-1# show 
ge-0/0/1 {
    unit 0;
}
#My Second Comment Uses A Hash Character
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# delete ge-0/0/2  

[edit interfaces]
lab@vMX-1# set ge-0/0/2 unit 0 

[edit interfaces]
lab@vMX-1# show 
ge-0/0/1 {
    unit 0;
}
ge-0/0/2 {
    unit 0;
}
ge-0/0/3 {
    unit 0;
}
ge-0/0/4 {
    unit 0;
}

[edit interfaces]
lab@vMX-1# show | compare 
[edit interfaces]
-  #My Second Comment Uses A Hash Character
   ge-0/0/2 { ... }

[edit interfaces]
lab@vMX-1# commit 
commit complete

[edit interfaces]
lab@vMX-1#

Other Quirky Behavior

There is some other quirky behavior with the annotate command.

It appears that you can only annotate statements at your current level in the configuration. For example, you can’t ‘annotate protocols ospf area 0 “comment”’ instead you need to edit down to protocols ospf.

lab@vMX-1# annotate protocols ospf area
                                   ^
syntax error, expecting ';', [Enter], or '|'.
lab@vMX-1# annotate protocols ospf area 

lab@vMX-1# edit protocols ospf            

[edit protocols ospf]
lab@vMX-1# annotate area 0 "Another Comment Goes Here" 

[edit protocols ospf]
lab@vMX-1# show 
/* Another Comment Goes Here */
area 0.0.0.0 {
    interface ge-0/0/1.0;
}

[edit protocols ospf]
lab@vMX-1# top 

[edit]
lab@vMX-1# show | compare 
[edit protocols ospf]
+    /* Another Comment Goes Here */
     area 0.0.0.0 { ... }

[edit]
lab@vMX-1# commit 
commit complete

[edit]
lab@vMX-1#

The other strange behavior is the comment doesn’t show when you run a ‘show’ for the specific config statement. Look at the difference between showing the entire protocol stanza and showing the ospf area 0 stanza.

[edit]
lab@vMX-1# show protocols                
ospf {
    /* Another Comment Goes Here */
    area 0.0.0.0 {
        interface ge-0/0/1.0;
    }
}

[edit]
lab@vMX-1# show protocols ospf area 0    
interface ge-0/0/1.0;

[edit]
lab@vMX-1#

The comment also doesn’t show up if you use display set. I guess it makes sense since it is not a ‘set’ command.

[edit]
lab@vMX-1# show protocols ospf 
/* Another Comment Goes Here */
area 0.0.0.0 {
    interface ge-0/0/1.0;
}

[edit]
lab@vMX-1# show protocols ospf | display set 
set protocols ospf area 0.0.0.0 interface ge-0/0/1.0

[edit]
lab@vMX-1#

Multi-Line Comments

If you are editing a config file offline and then loading it onto the device, you can add multi-line comments before a config statement by starting with ‘/*’ and ending with ‘*/’.

Sneakily, you can also do this with a load merge terminal relative.

[edit]
lab@vMX-1# show protocols ospf 
/* Another Comment Goes Here */
area 0.0.0.0 {
    interface ge-0/0/1.0;
}

[edit]
lab@vMX-1# edit protocols ospf area 0 

[edit protocols ospf area 0.0.0.0]
lab@vMX-1# load merge terminal relative 
[Type ^D at a new line to end input]
/*Can
We
Do
Multi-Line Comments
With A Merge Terminal*/  
interface ge-0/0/1.0;
<CTRL-D>
load complete

[edit protocols ospf area 0.0.0.0]
lab@vMX-1# top 

[edit]
lab@vMX-1# show | compare 
[edit protocols ospf area 0.0.0.0]
+     /*Can
+     We
+     Do
+     Multi-Line Comments
+     With A Merge Terminal*/
      interface ge-0/0/1.0 { ... }

[edit]
lab@vMX-1# commit 
commit complete

[edit]
lab@vMX-1# show protocols ospf 
/* Another Comment Goes Here */
area 0.0.0.0 {
    /*Can
    We
    Do
    Multi-Line Comments
    With A Merge Terminal*/
    interface ge-0/0/1.0;
}

[edit]
lab@vMX-1#

The question becomes will a load merge terminal only work for the first interface? The answer appears to be no, it will work for any interface. Note that I specify the statement I want to annotate after closing the comment.

[edit]
lab@vMX-1# show protocols 
ospf {
    /* Another Comment Goes Here */
    area 0.0.0.0 {
        /*Can
        We
        Do
        Multi-Line Comments
        With A Merge Terminal*/
        interface ge-0/0/1.0;
    }
}

[edit]
lab@vMX-1# edit protocols ospf area 0 

[edit protocols ospf area 0.0.0.0]
lab@vMX-1# load merge terminal relative 
[Type ^D at a new line to end input]
/* Second 
Multi-Line Comment
With A Second
Interface */
interface ge-0/0/2.0;
<CTRL-D>
load complete

[edit protocols ospf area 0.0.0.0]
lab@vMX-1# show 
/*Can
We
Do
Multi-Line Comments
With A Merge Terminal*/
interface ge-0/0/1.0;
/* Second 
Multi-Line Comment
With A Second
Interface */
interface ge-0/0/2.0;

[edit protocols ospf area 0.0.0.0]
lab@vMX-1# top 

[edit]
lab@vMX-1# show protocols ospf 
/* Another Comment Goes Here */
area 0.0.0.0 {
    /*Can
    We
    Do
    Multi-Line Comments
    With A Merge Terminal*/
    interface ge-0/0/1.0;
    /* Second 
    Multi-Line Comment
    With A Second
    Interface */
    interface ge-0/0/2.0;
}

[edit]
lab@vMX-1# commit 
commit complete

[edit]
lab@vMX-1#

Summary

The key points to take away are:

  • Annotations allow us to add comments to the Junos configuration, and appear above the statement that was annotated
  • Annotations are removed by setting a blank annotation
  • There are two formats, either /* */ or #
  • Multi-line comments can be added by loading a file or a load merge terminal relative
  • Comments can be frustrating if you don’t know how to remove them

Leave a Comment

Your email address will not be published. Required fields are marked *