dellemc.enterprise_sonic.sonic_static_routes (2.4.0) — module

Manage static routes configuration on SONiC

| "added in version" 2.0.0 of dellemc.enterprise_sonic"

Authors: Shade Talabi (@stalabi1)

Install collection

Install with ansible-galaxy collection install dellemc.enterprise_sonic:==2.4.0


Add to requirements.yml

  collections:
    - name: dellemc.enterprise_sonic
      version: 2.4.0

Description

This module provides configuration management of static routes for devices running SONiC

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

# Using merged
#
# Before State:
# -------------
#
# sonic# show running-configuration | grep "ip route"
# (No "ip route" configuration present)

  - name: Merge static routes configurations
    dellemc.enterprise_sonic.sonic_static_routes:
    config:
      - vrf_name: 'default'
        static_list:
         - prefix: '2.0.0.0/8'
           next_hops:
             - index:
                 interface: 'Ethernet4'
               metric: 1
               tag: 2
               track: 3
             - index:
                next_hop: '3.0.0.0'
               metric: 2
               tag: 4
               track: 8
      - vrf_name: 'VrfReg1'
        static_list:
          - prefix: '3.0.0.0/8'
            next_hops:
              - index:
                  interface: 'eth0'
                  nexthop_vrf: 'VrfReg2'
                  next_hop: '4.0.0.0'
                metric: 4
                tag: 5
                track: 6
              - index:
                  blackhole: True
                metric: 10
                tag: 20
                track: 30
    state: merged
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# After State:
# ------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 2.0.0.0/8 3.0.0.0 tag 4 track 8 2
# ip route 2.0.0.0/8 interface Ethernet4 tag 2 track 3 1
# ip route vrf VrfReg1 3.0.0.0/8 4.0.0.0 interface Management 0 nexthop-vrf VrfReg2 tag 5 track 6 4
# ip route vrf VrfReg1 3.0.0.0/8 blackhole tag 20 track 30 10
#
#
# Modifying previous merge

  - name: Modify static routes configurations
    dellemc.enterprise_sonic.sonic_static_routes:
    config:
      - vrf_name: 'VrfReg1'
        static_list:
          - prefix: '3.0.0.0/8'
            next_hops:
              - index:
                  blackhole: True
                metric: 11
                tag: 22
                track: 33
    state: merged
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# After State:
# ------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 2.0.0.0/8 3.0.0.0 tag 4 track 8 2
# ip route 2.0.0.0/8 interface Ethernet4 tag 2 track 3 1
# ip route vrf VrfReg1 3.0.0.0/8 4.0.0.0 interface Management 0 nexthop-vrf VrfReg2 tag 5 track 6 4
# ip route vrf VrfReg1 3.0.0.0/8 blackhole tag 22 track 33 11


# Using overridden
#
# Before State:
# -------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 4.0.0.0/8 2.0.0.0 tag 4 track 8 2

  - name: Override static routes configurations
    dellemc.enterprise_sonic.sonic_static_routes:
    config:
      - vrf_name: 'VrfReg2'
        static_list:
          - prefix: '3.0.0.0/8'
            next_hops:
              - index:
                  blackhole: True
                metric: 10
                tag: 20
                track: 30
    state: overridden
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# After State:
# ------------
#
# sonic# show running-configuration | grep "ip route"
# ip route vrf VrfReg2 3.0.0.0/8 blackhole tag 20 track 30 10


# Using Replaced
#
# Before State:
# -------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 4.0.0.0/8 2.0.0.0 tag 4 track 8 2

  - name: Replace static routes configurations
    dellemc.enterprise_sonic.sonic_static_routes:
    config:
      - vrf_name: 'default'
        static_list:
          - prefix: '4.0.0.0/8'
            next_hops:
              - index:
                  blackhole: True
                metric: 5
                tag: 10
                track: 15
    state: replaced
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# After State:
# ------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 4.0.0.0/8 blackhole tag 10 track 15 5


# Using deleted
#
# Before State:
# -------------
#
# sonic# show running-configuration | grep "ip route"
# ip route 2.0.0.0/8 3.0.0.0 tag 4 track 8 2
# ip route 2.0.0.0/8 interface Ethernet4 tag 2 track 3 1
# ip route vrf VrfReg1 3.0.0.0/8 4.0.0.0 interface Management 0 nexthop-vrf VrfReg2 tag 5 track 6 4
# ip route vrf VrfReg1 3.0.0.0/8 blackhole tag 22 track 33 11

  - name: Delete static routes configurations
    dellemc.enterprise_sonic.sonic_static_routes:
    config:
      - vrf_name: 'default'
        static_list:
         - prefix: '2.0.0.0/8'
           next_hops:
             - index:
                 interface: 'Ethernet4'
      - vrf_name: 'VrfReg1'
    state: deleted

Inputs

    
state:
    choices:
    - merged
    - deleted
    - overridden
    - replaced
    default: merged
    description:
    - The state of the configuration after module completion.
    type: str

config:
    description:
    - Manages 'static_routes' configurations
    elements: dict
    suboptions:
      static_list:
        description:
        - A list of 'static_routes' configurations.
        elements: dict
        suboptions:
          next_hops:
            description:
            - A list of next-hops to be utilised for the static route being specified.
            elements: dict
            suboptions:
              index:
                description:
                - An identifier utilised to uniquely reference the next-hop.
                required: true
                suboptions:
                  blackhole:
                    default: false
                    description:
                    - Indicates that packets matching this route should be discarded.
                    type: bool
                  interface:
                    description:
                    - The reference to a base interface.
                    type: str
                  next_hop:
                    description:
                    - The next-hop that is to be used for the static route.
                    type: str
                  nexthop_vrf:
                    description:
                    - Name of the next-hop network instance for leaked routes.
                    type: str
                type: dict
              metric:
                description:
                - Specifies the preference of the next-hop entry when it is injected into
                  the RIB.
                type: int
              tag:
                description:
                - The tag value for the static route.
                type: int
              track:
                description:
                - The IP SLA track ID for static route.
                type: int
            type: list
          prefix:
            description:
            - Destination prefix for the static route, either IPv4 or IPv6.
            required: true
            type: str
        type: list
      vrf_name:
        description:
        - Name of the configured VRF on the device.
        required: true
        type: str
    type: list

Outputs

after:
  description: The resulting configuration model invocation.
  returned: when changed
  sample: "The configuration returned will always be in the same format\n of the parameters\
    \ above.\n"
  type: list
after(generated):
  description: The generated configuration model invocation.
  returned: when C(check_mode)
  sample: "The configuration returned will always be in the same format\n of the parameters\
    \ above.\n"
  type: list
before:
  description: The configuration prior to the model invocation.
  returned: always
  sample: "The configuration returned will always be in the same format\n of the parameters\
    \ above.\n"
  type: list
commands:
  description: The set of commands pushed to the remote device.
  returned: always
  sample:
  - command 1
  - command 2
  - command 3
  type: list