cisco.ios.ios_static_routes 模块 – 配置静态路由的资源模块。

注意

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

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

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

要在 playbook 中使用它,请指定: cisco.ios.ios_static_routes

cisco.ios 1.0.0 中的新增功能

概要

  • 此模块配置和管理 IOS 平台上的静态路由。

参数

参数

注释

config

列表 / 元素=字典

静态路由选项的字典

address_families

列表 / 元素=字典

用于静态路由的地址族

afi

字符串 / 必需

顶级地址族指示器。

选项

  • "ipv4"

  • "ipv6"

routes

列表 / 元素=字典

配置静态路由

dest

字符串 / 必需

带子网掩码的目标前缀

next_hops

列表 / 元素=字典

下一跳地址或接口

dhcp

布尔值

从 DHCP 获取默认网关

选项

  • false

  • true

distance_metric

整数

此路由的距离度量

forward_router_address

字符串

转发路由器的地址

global

布尔值

下一跳地址是全局的

选项

  • false

  • true

interface

字符串

直接连接静态路由的接口

multicast

布尔值

多播路由

选项

  • false

  • true

name

字符串

指定下一跳的名称

permanent

布尔值

永久路由

选项

  • false

  • true

tag

整数

设置此路由的标签

请参考厂商文档以了解有效值。

track

整数

根据具有跟踪对象编号的跟踪项目安装路由。

跟踪不支持多播

请参考厂商文档以了解有效值。

unicast

布尔值

单播路由(ipv6 特定)

选项

  • false

  • true

topology

字符串

为拓扑路由/转发实例配置静态路由

注意,VRF 和拓扑只能与多播一起使用,并且拓扑应该在使用之前预先存在

vrf

字符串

IP VPN 路由/转发实例名称。

注意,对于 IPV4/IPV6,VRF 路由表应该在配置之前预先存在。

注意,如果没有提供 vrf 信息,则应在全局 vrf 下配置路由。

running_config

字符串

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

此选项的值应该是通过执行命令 **show running-config | include ip route|ipv6 route** 从 IOS 设备接收到的输出。

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

state

字符串

配置应保留到的状态

状态 *rendered*、*gathered* 和 *parsed* 不会对设备进行任何更改。

状态 *rendered* 将 config 选项中的配置转换为特定于平台的 CLI 命令,这些命令将在结果中的 *rendered* 密钥中返回。对于状态 *rendered*,不需要与远程主机的活动连接。

状态 *gathered* 将从设备获取运行配置,并将其转换为与资源模块 argspec 匹配的格式的结构化数据,并将值返回在结果中的 *gathered* 密钥中。

状态 *parsed* 从 running_config 选项读取配置,并根据资源模块参数将其转换为 JSON 格式,并将值返回在结果中的 *parsed* 密钥中。running_config 选项的值应与在设备上执行的命令 *show running-config | include ip route|ipv6 route* 的输出格式相同。对于状态 *parsed*,不需要与远程主机的活动连接。

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

注释

注意

示例

# Using merged

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route

- name: Merge provided configuration with device configuration
  cisco.ios.ios_static_routes:
    config:
      - vrf: blue
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.0/24
                next_hops:
                  - forward_router_address: 192.0.2.1
                    name: merged_blue
                    tag: 50
                    track: 150
      - address_families:
          - afi: ipv4
            routes:
              - dest: 198.51.100.0/24
                next_hops:
                  - forward_router_address: 198.51.101.1
                    name: merged_route_1
                    distance_metric: 110
                    tag: 40
                    multicast: true
                  - forward_router_address: 198.51.101.2
                    name: merged_route_2
                    distance_metric: 30
                  - forward_router_address: 198.51.101.3
                    name: merged_route_3
          - afi: ipv6
            routes:
              - dest: 2001:DB8:0:3::/64
                next_hops:
                  - forward_router_address: 2001:DB8:0:3::2
                    name: merged_v6
                    tag: 105
    state: merged

# Task Output
# -----------
#
# before:
# - {}
# commands:
# - ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
# - ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
# - ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
# - ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
# - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
# after:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: merged_route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: merged_route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: merged_route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: merged_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: merged_blue
#         tag: 50
#         track: 150
#   vrf: blue

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6

# Using replaced

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6

- name: Replace provided configuration with device configuration
  cisco.ios.ios_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 198.51.100.0/24
                next_hops:
                  - forward_router_address: 198.51.101.1
                    name: replaced_route
                    distance_metric: 175
                    tag: 70
                    multicast: true
    state: replaced

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: merged_route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: merged_route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: merged_route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: merged_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: merged_blue
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
# after:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - distance_metric: 175
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: replaced_route
#         tag: 70
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: merged_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: merged_blue
#         tag: 50
#         track: 150
#   vrf: blue

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6

# Using overridden

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6

- name: Override provided configuration with device configuration
  cisco.ios.ios_static_routes:
    config:
      - vrf: blue
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.0/24
                next_hops:
                  - forward_router_address: 192.0.2.1
                    name: override_vrf
                    tag: 50
                    track: 150
    state: overridden

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - distance_metric: 175
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: replaced_route
#         tag: 70
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: merged_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: merged_blue
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name override_vrf track 150
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
# - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
# after:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: override_vrf
#         tag: 50
#         track: 150
#   vrf: blue

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name override_vrf track 150

# Using deleted

# Before state:
# -------------
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Delete the exact static routes, with all the static routes explicitly mentioned in want
  cisco.ios.ios_static_routes:
    config:
      - vrf: blue
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.0/24
                next_hops:
                  - forward_router_address: 192.0.2.1
                    name: test_vrf
                    tag: 50
                    track: 150
      - address_families:
          - afi: ipv4
            routes:
              - dest: 198.51.100.0/24
                next_hops:
                  - forward_router_address: 198.51.101.1
                    name: route_1
                    distance_metric: 110
                    tag: 40
                    multicast: true
                  - forward_router_address: 198.51.101.2
                    name: route_2
                    distance_metric: 30
                  - forward_router_address: 198.51.101.3
                    name: route_3
          - afi: ipv6
            routes:
              - dest: 2001:DB8:0:3::/64
                next_hops:
                  - forward_router_address: 2001:DB8:0:3::2
                    name: test_v6
                    tag: 105
    state: deleted

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
# after: {}

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route

# Using deleted - delete based on specific routes

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Delete destination specific static routes
  cisco.ios.ios_static_routes:
    config:
      - address_families:
          - afi: ipv4
            routes:
              - dest: 198.51.100.0/24
    state: deleted

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# after:
# - address_families:
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

# Using deleted - delete based on vrfs

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Delete vrf specific static routes
  cisco.ios.ios_static_routes:
    config:
      - vrf: blue
    state: deleted

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# after:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105

# After state:
# ------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

# Using deleted - delete all

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Delete ALL configured static routes
  cisco.ios.ios_static_routes:
    state: deleted

# Task Output
# -----------
#
# before:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue
# commands:
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
# - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# after: {}

# After state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route

# Using gathered

# Before state:
# -------------
#
# vios#show running-config | include ip route|ipv6 route
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Gather facts of static routes
  cisco.ios.ios_static_routes:
    config:
    state: gathered

# Task Output
# -----------
#
# gathered:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue

# Using rendered

- name: Render the commands for provided configuration
  cisco.ios.ios_static_routes:
    config:
      - vrf: blue
        address_families:
          - afi: ipv4
            routes:
              - dest: 192.0.2.0/24
                next_hops:
                  - forward_router_address: 192.0.2.1
                    name: test_vrf
                    tag: 50
                    track: 150
      - address_families:
          - afi: ipv4
            routes:
              - dest: 198.51.100.0/24
                next_hops:
                  - forward_router_address: 198.51.101.1
                    name: route_1
                    distance_metric: 110
                    tag: 40
                    multicast: true
                  - forward_router_address: 198.51.101.2
                    name: route_2
                    distance_metric: 30
                  - forward_router_address: 198.51.101.3
                    name: route_3
          - afi: ipv6
            routes:
              - dest: 2001:DB8:0:3::/64
                next_hops:
                  - forward_router_address: 2001:DB8:0:3::2
                    name: test_v6
                    tag: 105
    state: rendered

# Task Output
# -----------
#
# rendered:
# - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# - ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# - ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# - ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# - ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

# Using parsed

# File: parsed.cfg
# ----------------
#
# ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
# ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
# ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
# ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
# ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6

- name: Parse the provided configuration
  cisco.ios.ios_static_routes:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Task Output
# -----------
#
# parsed:
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 198.51.100.0/24
#       next_hops:
#       - forward_router_address: 198.51.101.3
#         name: route_3
#       - distance_metric: 30
#         forward_router_address: 198.51.101.2
#         name: route_2
#       - distance_metric: 110
#         forward_router_address: 198.51.101.1
#         multicast: true
#         name: route_1
#         tag: 40
#   - afi: ipv6
#     routes:
#     - dest: 2001:DB8:0:3::/64
#       next_hops:
#       - forward_router_address: 2001:DB8:0:3::2
#         name: test_v6
#         tag: 105
# - address_families:
#   - afi: ipv4
#     routes:
#     - dest: 192.0.2.0/24
#       next_hops:
#       - forward_router_address: 192.0.2.1
#         name: test_vrf
#         tag: 50
#         track: 150
#   vrf: blue

返回值

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

描述

after

列表 / 元素=字符串

模块完成后的结构化数据配置。

返回:已更改时

示例: ["返回的配置将始终与上述参数的格式相同。"]

before

列表 / 元素=字符串

模块调用之前的结构化数据配置。

返回值: 始终

示例: ["返回的配置将始终与上述参数的格式相同。"]

commands

列表 / 元素=字符串

推送到远程设备的命令集

返回值: 始终

示例: ["ip route vrf test 172.31.10.0 255.255.255.0 10.10.10.2 name new_test multicast"]

gathered

列表 / 元素=字符串

从远程主机获取的运行配置转换后的结构化数据配置

返回值:stategathered

示例: ["返回的配置始终与上述参数格式相同。\n"]

parsed

列表 / 元素=字符串

running_config 选项值的转换后的结构化数据配置

返回值:stateparsed

示例: ["返回的配置始终与上述参数格式相同。\n"]

rendered

列表 / 元素=字符串

根据 config 选项的值生成的CLI命令集

返回值:staterendered

示例: ["ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3", "ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6"]

作者

  • Sagar Paul (@KB-perByte)

  • Sumit Jaiswal (@justjais)