cisco.nxos.nxos_static_routes 模块 – 静态路由资源模块

注意

此模块是 cisco.nxos 集合 (版本 9.2.1) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install cisco.nxos

要在 playbook 中使用它,请指定: cisco.nxos.nxos_static_routes

cisco.nxos 1.0.0 中的新增功能

概要

  • 此模块配置和管理 Cisco NX-OS 平台上静态路由的属性。

参数

参数

注释

config

列表 / 元素=字典

静态路由配置列表

address_families

列表 / 元素=字典

指定静态路由所属的地址族。

afi

字符串 / 必需

指定顶级地址族指示器。

选项

  • "ipv4"

  • "ipv6"

routes

列表 / 元素=字典

指定静态路由配置的字典

dest

字符串 / 必需

静态路由的目标前缀

地址格式为 <ipv4/v6 地址>/<掩码>

对于 IPv4,掩码是 0-32 范围内的数字;对于 IPv6,掩码是 0-128 范围内的数字

next_hops

列表 / 元素=字典

要采取的路由详情

admin_distance

整数

路由的优先级或管理距离 (范围 1-255)

dest_vrf

字符串

目标的 VRF

forward_router_address

字符串

下一跳路由器的 IP 地址

interface

字符串

要使用的出站接口。对于除“Null0”以外的任何接口,都应配置下一跳 IP 地址。

route_name

字符串

静态路由的名称

tag

整数

路由标签值(数值)

track

整数

跟踪值(范围 1-512)。在添加路由之前,必须已经在设备上配置跟踪。

vrf

字符串

静态路由所属的 VRF

running_config

字符串

此选项仅与状态 *parsed* 一起使用。

此选项的值应是从 NX-OS 设备接收到的输出,通过按顺序执行以下命令获得:**show running-config | include ‘^ip(v6* route’)** 和 **show running-config | section ‘^vrf context’**。

状态 *parsed* 从 running_config 选项读取配置并将其转换为 Ansible 结构化数据,该数据符合资源模块的 argspec,然后该值将返回到结果中的 *parsed* 键中。

state

字符串

配置应保留的状态

选项

  • "deleted"

  • "merged" ← (默认)

  • "overridden"

  • "replaced"

  • "gathered"

  • "rendered"

  • "parsed"

备注

注意

  • 在运行 NX-OS 9.3.6 的 CML 上的 Nexus 9300v 上进行了测试。

  • 不支持 Cisco MDS

  • 为不存在的 VRF 配置路由时,将创建 VRF 并将其添加到其中。

  • 删除 VRF 的路由时,将删除 VRF 内的所有路由,但不会删除 VRF 本身。

示例

# Using deleted - delete all

# Before state:
# -------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.32/28 192.0.2.12 name new_route
# ip route 192.0.2.26/24 192.0.2.13 tag 12
# switch# show running-config | section '^vrf context'

- name: Delete all routes
  cisco.nxos.nxos_static_routes:
    state: deleted

# Task Output
# -----------
#
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.0/24
#             next_hops:
#               - forward_router_address: 192.0.2.13
#                 tag: 12
#           - dest: 192.0.2.32/28
#             next_hops:
#               - forward_router_address: 192.0.2.12
#                 route_name: new_route
# commands:
# - no ip route 192.0.2.0/24 192.0.2.13 tag 12
# - no ip route 192.0.2.32/28 192.0.2.12 name new_route
# after: []

# After state:
# ------------
# switch# show running-config | include '^ip(v6)* route'
# switch# show running-config | section '^vrf context'

# Using deleted - vrf based

# Before state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ip route 192.0.2.64/28 192.0.2.22 tag 4
# ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
# ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5

- name: Delete routes based on VRF
  cisco.nxos.nxos_static_routes:
    config:
      - vrf: trial_vrf
    state: deleted

# Task Output
# -----------
#
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.64/28
#             next_hops:
#               - forward_router_address: 192.0.2.22
#                 tag: 4
#               - admin_distance: 1
#                 forward_router_address: 192.0.2.23
#                 route_name: merged_route
#       - afi: ipv6
#         routes:
#           - dest: '2200:10::/36'
#             next_hops:
#               - admin_distance: 5
#                 dest_vrf: dest
#                 forward_router_address: '2048:ae12::1'
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12
# commands:
# - vrf context trial_vrf
# - no ip route 192.0.2.64/28 192.0.2.22 tag 4
# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
# - no ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12

# After state:
# -----------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf

# Using deleted - afi based

# Before state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ip route 192.0.2.64/28 192.0.2.22 tag 4
# ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
# ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5

- name: Delete routes based on AFI in a VRF
  cisco.nxos.nxos_static_routes:
    config:
      - vrf: trial_vrf
        address_families:
          - afi: ipv4
    state: deleted

# Task Output
# -----------
#
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.64/28
#             next_hops:
#               - forward_router_address: 192.0.2.22
#                 tag: 4
#               - admin_distance: 1
#                 forward_router_address: 192.0.2.23
#                 route_name: merged_route
#       - afi: ipv6
#         routes:
#           - dest: '2200:10::/36'
#             next_hops:
#               - admin_distance: 5
#                 dest_vrf: dest
#                 forward_router_address: '2048:ae12::1'
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12
# commands:
# - vrf context trial_vrf
# - no ip route 192.0.2.64/28 192.0.2.22 tag 4
# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
# after:
#   - address_families:
#       - afi: ipv6
#         routes:
#           - dest: '2200:10::/36'
#             next_hops:
#               - admin_distance: 5
#                 dest_vrf: dest
#                 forward_router_address: '2048:ae12::1'
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12

# After state:
# -----------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5

# Using merged

# Before state:
# -------------
# switch# show running-config | include '^ip(v6)* route'
# switch# show running-config | section '^vrf context'

- name: Merge new static route configuration
  cisco.nxos.nxos_static_routes:
    config:
      - vrf: trial_vrf
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.64/24
                next_hops:
                  - forward_router_address: 192.0.2.22
                    tag: 4
                    admin_distance: 2
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.16/24
                next_hops:
                  - forward_router_address: 192.0.2.24
                    route_name: new_route
          - afi: ipv6
            routes:
              - dest: '2001:db8::/64'
                next_hops:
                  - interface: eth1/3
                    forward_router_address: '2001:db8::12'
    state: merged

# Task Output
# -----------
#
# before:[]
# commands:
# - vrf context trial_vrf
# - ip route 192.0.2.64/24 192.0.2.22 tag 4 2
# - ip route 192.0.2.16/24 192.0.2.24 name new_route
# - ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12
# after:
#     - vrf: trial_vrf
#       address_families:
#       - afi: ipv4
#         routes:
#         - dest: 192.0.2.64/24
#           next_hops:
#           - forward_router_address: 192.0.2.22
#             tag: 4
#             admin_distance: 2
#     - address_families:
#       - afi: ipv4
#         routes:
#         - dest: 192.0.2.16/24
#           next_hops:
#           - forward_router_address: 192.0.2.24
#             route_name: new_route
#       - afi: ipv6
#         routes:
#         - dest: 2001:db8::/64
#           next_hops:
#           - interface: eth1/3
#             forward_router_address: 2

# After state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/24 192.0.2.24 name new_route
# ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
#   ip route 192.0.2.0/24 192.0.2.22 tag 4 2

# Using overridden

# Before state:
# -------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ip route 192.0.2.64/28 192.0.2.22 tag 4
# ip route 192.0.2.64/28 192.0.2.23 name merged_route 1

- name: Overridden existing static route configuration with new configuration
  cisco.nxos.nxos_static_routes:
    config:
      - vrf: trial_vrf
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.16/28
                next_hops:
                  - forward_router_address: 192.0.2.23
                    route_name: overridden_route1
                    admin_distance: 3
                  - forward_router_address: 192.0.2.45
                    route_name: overridden_route2
                    dest_vrf: destinationVRF
                    interface: Ethernet1/2
    state: overridden

# Task Output
# -----------
#
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.64/28
#             next_hops:
#               - forward_router_address: 192.0.2.22
#                 tag: 4
#               - admin_distance: 1
#                 forward_router_address: 192.0.2.23
#                 route_name: merged_route
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12
# commands:
# - no ip route 192.0.2.16/28 192.0.2.24 name new_route
# - no ip route 192.0.2.80/28 192.0.2.26 tag 12
# - vrf context trial_vrf
# - no ip route 192.0.2.64/28 192.0.2.22 tag 4
# - no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
# - ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3
# - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - admin_distance: 3
#                 forward_router_address: 192.0.2.23
#                 route_name: overridden_route1
#               - dest_vrf: destinationVRF
#                 forward_router_address: 192.0.2.45
#                 interface: Ethernet1/2
#                 route_name: overridden_route2
#    vrf: trial_vrf

# After state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
#   ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3
#   ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name overridden_route2

# Using replaced

# Before state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.24 name new_route
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ip route 192.0.2.64/28 192.0.2.22 tag 4
# ip route 192.0.2.64/28 192.0.2.23 name merged_route 1

- name: Replaced the existing static configuration of a prefix with new configuration
  cisco.nxos.nxos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.16/28
                next_hops:
                  - forward_router_address: 192.0.2.23
                    route_name: replaced_route1
                    admin_distance: 3
                  - forward_router_address: 192.0.2.45
                    route_name: replaced_route2
                    dest_vrf: destinationVRF
                    interface: Ethernet1/2
    state: replaced

# Task Output
# -----------
#
# before:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.64/28
#             next_hops:
#               - forward_router_address: 192.0.2.22
#                 tag: 4
#               - admin_distance: 1
#                 forward_router_address: 192.0.2.23
#                 route_name: merged_route
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - forward_router_address: 192.0.2.24
#                 route_name: new_route
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12
# commands:
# - no ip route 192.0.2.16/28 192.0.2.24 name new_route
# - ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
# - ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
# after:
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.64/28
#             next_hops:
#               - forward_router_address: 192.0.2.22
#                 tag: 4
#               - admin_distance: 1
#                 forward_router_address: 192.0.2.23
#                 route_name: merged_route
#     vrf: trial_vrf
#   - address_families:
#       - afi: ipv4
#         routes:
#           - dest: 192.0.2.16/28
#             next_hops:
#               - admin_distance: 3
#                 forward_router_address: 192.0.2.23
#                 route_name: replaced_route1
#               - dest_vrf: destinationVRF
#                 forward_router_address: 192.0.2.45
#                 interface: Ethernet1/2
#                 route_name: replaced_route2
#           - dest: 192.0.2.80/28
#             next_hops:
#               - forward_router_address: 192.0.2.26
#                 tag: 12

# After state:
# ------------
#
# switch# show running-config | include '^ip(v6)* route'
# ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
# ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
# ip route 192.0.2.80/28 192.0.2.26 tag 12
# switch# show running-config | section '^vrf context'
# vrf context trial_vrf
# ip route 192.0.2.64/28 192.0.2.22 tag 4
# ip route 192.0.2.64/28 192.0.2.23 name merged_route 1


# Using gathered

# Before state:
# -------------
#
# switch# show running-config | include '^ip(v6)* route'
# ipv6 route 2001:db8:12::/32  2001:db8::12
# switch# show running-config | section '^vrf context'
# vrf context Test
#    ip route 192.0.2.48/28 192.0.2.13
#    ip route 192.0.2.48/28 192.0.2.14 5

- name: Gather the existing configuration
  cisco.nxos.nxos_static_routes:
    state: gathered

# Task Output
# -----------
#
# gathered:
#     - vrf: Test
#       address_families:
#         - afi: ipv4
#           routes:
#             - dest: 192.0.2.48/28
#               next_hops:
#                 - forward_router_address: 192.0.2.13
#
#                 - forward_router_address: 192.0.2.14
#                   admin_distance: 5
#
#     - address_families:
#         - afi: ipv6
#           routes:
#             - dest: 2001:db8:12::/32
#               next_hops:
#                 - forward_router_address: 2001:db8::12


# Using rendered

- name: Render required configuration to be pushed to the device
  cisco.nxos.nxos_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.48/28
                next_hops:
                  - forward_router_address: 192.0.2.13
          - afi: ipv6
            routes:
              - dest: 2001:db8::/64
                next_hops:
                  - interface: eth1/3
                    forward_router_address: 2001:db8::12
    state: rendered

# Task Output
# -----------
#
# rendered:
#   vrf context default
#   ip route 192.0.2.48/28 192.0.2.13
#   ipv6 route 2001:db8::/64 Ethernet1/3 2001:db8::12

# Using parsed

- name: Parse the config to structured data
  cisco.nxos.nxos_static_routes:
    state: parsed
    running_config: |
      ipv6 route 2002:db8:12::/32 2002:db8:12::1
      vrf context Test
        ip route 192.0.2.48/28 192.0.2.13
        ip route 192.0.2.48/28 192.0.2.14 5

# Task Output
# -----------
#
# parsed:
#     - vrf: Test
#       address_families:
#         - afi: ipv4
#           routes:
#             - dest: 192.0.2.48/28
#               next_hops:
#                 - forward_router_address: 192.0.2.13
#                 - forward_router_address: 192.0.2.14
#                   admin_distance: 5
#     - address_families:
#         - afi: ipv6
#           routes:
#             - dest: 2002:db8:12::/32
#               next_hops:
#                 - forward_router_address: 2002:db8:12::1

返回值

公共返回值已在此处记录,以下是此模块独有的字段

描述

after

列表 / 元素=字符串

模块执行后的结果配置。

返回:发生更改时

示例: ["This output will always be in the same format as the module argspec.\n"]

before

列表 / 元素=字符串

模块执行前的配置。

返回:当 *state* 为 mergedreplacedoverriddendeletedpurged

示例: ["This output will always be in the same format as the module argspec.\n"]

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回:当 *state* 为 mergedreplacedoverriddendeletedpurged

示例: ["ip route 192.0.2.16/28 192.0.2.24 name new_route", "vrf context trial_vrf", "ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3"]

gathered

列表 / 元素=字符串

从远程设备收集的网络资源事实,以结构化数据形式呈现。

返回:当 *state* 为 gathered

示例: ["This output will always be in the same format as the module argspec.\n"]

parsed

列表 / 元素=字符串

根据模块 argspec 将 *running_config* 选项中提供的设备原生配置解析为结构化数据。

返回:当 *state* 为 parsed

示例: ["This output will always be in the same format as the module argspec.\n"]

rendered

列表 / 元素=字符串

以设备原生格式呈现的任务中提供的配置(离线)。

返回:当 *state* 为 rendered

示例: ["ip route 192.0.2.16/28 192.0.2.24 name new_route", "vrf context trial_vrf", "ip route 192.0.2.16/28 192.0.2.23 name overridden_route1 3"]

作者

  • Adharsh Srivats Rangarajan (@adharshsrivatsr)

  • Sagar Paul (@KB-perByte)