Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Example: Using Chef for Junos OS to Configure Ethernet Switching on MX Series Routers

 

This example shows how you can use resources in the netdev cookbook to write recipes that configure the switching interfaces on MX Series routers running the Chef client. For more information about the light-weight resources in the netdev cookbook, see Chef for Junos OS at https://docs.chef.io/junos.html.

Requirements

This example uses the following hardware and software components:

  • A properly set up and configured Chef workstation and Chef server

  • An MX Series router that the Chef client manages

  • Junos OS Release 16.1 or later

Before you begin, the number of aggregated Ethernet interfaces supported on the router must already be configured before you run the Chef client.

  • To verify that a sufficient number of aggregated Ethernet interfaces has been configured, use the show chassis aggregated-devices configuration mode CLI command. Use the set chassis aggregated-devices ethernet device-count command to set the number of supported aggregated Ethernet interfaces.

  • If the number of aggregated Ethernet interfaces supported on the router is not already configured, log in to the router, enter configuration mode, and configure the number of aggregated Ethernet interfaces supported:

    root@router-node# set chassis aggregated-devices ethernet device-count 2

    root@router-node# commit and-quit

Overview

This example takes you through using Chef for Junos OS to configure the switching interfaces on an MX Series router.

In this example, you create a cookbook, called netdev_router, that is based on the netdev cookbook. Within the cookbook, you create four recipes:

  • vlan_create recipe—Defines netdev_vlan resources for the VLANs shown in Table 1.

  • interface_create recipe—Defines the netdev_interface resources for the interfaces shown in Table 2.

  • l2interface_create recipe—Defines the netdev_l2_interface resources for the interfaces shown in Table 2.

  • lag_interface_create recipe—Defines netdev_lag and netdev_l2_interface resources for the link aggregation group (LAG ) interfaces shown in Table 3.

Table 1: VLANs Defined in the vlan_create Recipe

Name

VLAN ID

Description

blue

100

Chef-created blue VLAN

green

200

Chef-created green VLAN

red

300

Chef-created red VLAN

Table 2: Interfaces Defined in the interface_create and l2interface_create Recipes

Name

Port Mode

VLAN Membership

Description

ge-1/0/1

Access

blue

Chef-created interface

ge-1/0/2

Access

green

Chef-created interface

ge-1/0/3

Access

red

Chef-created interface

Table 3: LAGs Defined in the lag_interface_create Recipe

Name

Member
Interfaces

Mininum
Links

LACP

Port
Mode

VLAN
Membership

Description

ae0

ge-1/0/6
ge-1/0/7

1

Active

Trunk

blue, green, red

Chef-created LAG interface

ae1

ge-1/0/8
ge-1/0/9

1

Active

Trunk

blue, green, red

Chef-created LAG interface

In your own implementation of Chef for Junos OS, you can structure recipes in any way that makes sense for deploying and managing your switching resources. The recipes used in this example are simply one way of doing so.

After you create the recipes, you upload the cookbook to the Chef server and add the recipes to the run list for the managed router. Finally, you run the Chef client on the router. The client then uses the Junos OS providers in the netdev cookbook to implement the configuration described in the recipes.

Note

The number of aggregated Ethernet interfaces supported on the router must already be configured before you run the Chef client.

Configuration

Step-by-Step Procedure

To configure the router by using Chef for Junos OS:

  1. From the chef-repo directory on the Chef workstation, download the netdev cookbook and extract the cookbook files to the cookbooks directory.

    knife cookbook site download netdev

    tar -zxvf netdev-n.n.n.tar.gz -C cookbooks

  2. Copy the netdev cookbook to create a new cookbook, netdev_router, in the cookbooks directory.
  3. In an editor of your choice, write the vlan_create recipe for creating the blue, green, and red VLANs.
  4. Save the recipe in cookbooks/netdev_router/recipes/vlan_create.rb.
  5. In an editor of your choice, write the interface_create recipe, which configures the physical properties of the interfaces.
  6. Save the recipe in cookbooks/netdev_router/recipes/interface_create.rb.
  7. In an editor of your choice, write the l2interface_create recipe, which configures the Layer 2 properties of the interfaces.
  8. Save the recipe in cookbooks/netdev_router/recipes/l2interface_create.rb.
  9. In an editor of your choice, write the lag_interface_create recipe, which configures the LAG trunk interfaces.
  10. Save the recipe in cookbooks/netdev_router /recipes/lag_interface_create.rb.
  11. Upload the netdev_router cookbook to the Chef server.

    $ knife cookbook upload netdev_router

  12. Edit the node object that represents the router.

    $ knife node edit router_node_name

    Knife starts your editor and opens a JSON file that contains the node attributes.

  13. Enter the recipes in the run-list attribute and then save the JSON file.

    The order in which you enter the recipes matters—for example, the Chef client runs the interfaces_create recipe first because it is listed first.

  14. Log in as the root user.
  15. From the UNIX-level shell, run the Chef client.
    • If the Juniper Networks version of the Chef client is 2.x (for example, Chef client version 11.10.4_2.0), enter:

      %/opt/jet/chef/bin/ruby /opt/jet/chef/bin/chef-client -c /var/db/chef/client.rb

    • If the Juniper Networks version of the Chef client is 1.x (for example, Chef client version 11.10.4_1.1), enter:

      %/opt/sdk/chef/bin/ruby /opt/sdk/chef/bin/chef-client -c /var/db/chef/client.rb

    The Chef client displays status messages during its run to indicate its progress in performing the configuration. For example:

Results

From operational mode, confirm your configuration by entering the show configuration | compare rollback 1 command. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

Note

The apply-macro statement under the ae0 and ae1 interface configuration is a normally hidden statement that is exposed when the configuration is generated by a Chef client.

Verification

Verifying the Status of the VLANs

Purpose

Verify the VLANs and VLAN memberships are correct.

Action

Use the show bridge domain command to verify VLAN membership.

Meaning

The output shows that the VLANs have been created correctly and contain the correct member interfaces.