cisco.ios.ios_vrf_global 模块 – 配置全局 VRF 定义的资源模块。

注意

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

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

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

要在剧本中使用它,请指定: cisco.ios.ios_vrf_global

cisco.ios 8.0.0 中的新增功能

概要

  • 此模块提供对 Cisco IOS 上 VRF 定义的声明式管理。

参数

参数

注释

config

字典

包含 VRF 设备配置的字典,包括 VRF 定义列表。

vrfs

列表 / 元素=字典

VRF 定义列表。

description

字符串

VRF 的具体描述

ipv4

字典

VRF IPv4 配置

multicast

字典

IPv4 多播配置

multitopology

布尔值

启用多播专用拓扑

选项

  • false

  • true

ipv6

字典

VRF IPv6 配置

multicast

字典

IPv6 多播配置

multitopology

布尔值

启用多播专用拓扑

选项

  • false

  • true

name

字符串 / 必需

VRF 的名称。

rd

字符串

指定路由区分符 (RD)。

route_target

字典

指定目标 VPN 扩展配置。

both

字符串

导出和导入目标 VPN 配置。

export

字符串

导出目标 VPN 配置。

import_config

字符串

导入目标 VPN 配置。

vnet

字典

虚拟网络配置。

tag

整数

用于标记与该 VNET 关联的数据包的标识符。

vpn

字典

根据 RFC 2685 中的规定,配置 VRF 的 vpn-id。

id

字符串

以 RFC 2685 格式配置 vpn-id。

running_config

字符串

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

此选项的值应为通过执行命令 show running-config | section ^vrf 从 IOS 设备接收到的输出。

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

state

字符串

配置应保留的状态

状态 renderedgatheredparsed 不会对设备进行任何更改。

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

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

状态 parsedrunning_config 选项读取配置,并根据资源模块参数将其转换为 JSON 格式,并将该值返回到结果中的 parsed 密钥中。running_config 选项的值应与命令 show running-config | section vrf 的输出格式相同。不需要与远程主机的连接。

状态 deleted 只删除此模块管理的 VRF 属性,而不会完全否定 VRF。从而保留 VRF 上下文中与地址族相关的配置。

状态 purged 将从目标设备中删除所有 VRF 定义。使用此状态时请谨慎。

有关更多详细信息,请参阅示例。

选项

  • "parsed"

  • "gathered"

  • "deleted"

  • "merged" ← (默认)

  • "replaced"

  • "rendered"

  • "overridden"

  • "purged"

备注

注意

示例

# Using merged

# Before state:
# -------------
#
# admin#show running-config | section ^vrf

- name: Merge provided configuration with device configuration
  cisco.ios.ios_vrf_global:
    config:
      vrfs:
        - name: VRF2
          description: This is a test VRF for merged state
          ipv4:
            multicast:
              multitopology: true
          ipv6:
            multicast:
              multitopology: true
          rd: "2:3"
          route_target:
            export: "192.0.2.0:100"
            import_config: "192.0.2.3:200"
          vpn:
            id: "2:45"
          vnet:
            tag: 200
    state: merged

# Task output
# -------------
#
# before: {}
#
# commands:
#   - vrf definition VRF2
#   - description This is a test VRF for merged state
#   - ipv4 multicast multitopology
#   - ipv6 multicast multitopology
#   - rd 2:3
#   - route-target export 192.0.2.0:100
#   - route-target import 192.0.2.3:200
#   - vnet tag 200
#   - vpn id 2:45
#
# after:
#   - name: VRF2
#     description: This is a test VRF for merged state
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "2:3"
#     route_target:
#       export: "192.0.2.0:100"
#       import_config: "192.0.2.3:200"
#     vnet:
#       tag: 200
#     vpn:
#       id: "2:45"

# After state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
#  vnet tag 200
#  description This is a test VRF for merged state
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 2:3
#  vpn id 2:45
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.3:200

# Using replaced

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
#  vnet tag 200
#  description This is a test VRF for merged state
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 2:3
#  vpn id 2:45
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.3:200

- name: Replace the provided configuration with the existing running configuration
  cisco.ios.ios_vrf_global:
    config:
      vrfs:
        - name: VRF7
          description: VRF7 description
          ipv4:
            multicast:
              multitopology: true
          ipv6:
            multicast:
              multitopology: true
          rd: "7:8"
          route_target:
            export: "198.51.100.112:500"
            import_config: "192.0.2.4:400"
          vpn:
            id: "5:45"
          vnet:
            tag: 300
    state: replaced

# Task Output:
# ------------
#
# before:
#   - name: VRF2
#     description: This is a test VRF for merged state
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "2:3"
#     route_target:
#       export: "192.0.2.0:100"
#       import_config: "192.0.2.3:200"
#     vnet:
#       tag: 200
#     vpn:
#       id: "2:45"
#
# commands:
# - vrf definition VRF7
# - description VRF7 description
# - ipv4 multicast multitopology
# - ipv6 multicast multitopology
# - rd 7:8
# - route-target export 198.51.100.112:500
# - route-target import 192.0.2.4:400
# - vnet tag 300
# - vpn id 5:45
#
# after:
#   - name: VRF2
#     description: This is a test VRF for merged state
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "2:3"
#     route_target:
#       export: "192.0.2.0:100"
#       import_config: "192.0.2.3:200"
#     vnet:
#       tag: 200
#     vpn:
#       id: "2:45
#   - name: VRF7
#     description: VRF7 description
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "7:8"
#     route_target:
#       export: "198.51.100.112:500"
#       import_config: "192.0.2.4:400"
#     vnet:
#       tag: 300
#     vpn:
#       id: "5:45"
#
# After state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
#  vnet tag 200
#  description This is a test VRF for merged state
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 2:3
#  vpn id 2:45
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.3:200
# vrf definition VRF7
#  vnet tag 300
#  description VRF7 description
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 7:8
#  route-target export 198.51.100.112:500
#  route-target import 192.0.2.4:400
#  vpn id 5:45

# Using Overridden

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
#  vnet tag 200
#  description This is a test VRF for merged state
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 2:3
#  vpn id 2:45
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.3:200
# vrf definition VRF7
#  vnet tag 300
#  description VRF7 description
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 7:8
#  route-target export 198.51.100.112:500
#  route-target import 192.0.2.4:400
#  vpn id 5:45

- name: Override the provided configuration with the existing running configuration
  cisco.ios.ios_vrf_global:
    config:
      vrfs:
        - name: VRF6
          description: VRF6 description
          ipv4:
            multicast:
              multitopology: true
          ipv6:
            multicast:
              multitopology: true
          rd: "6:7"
          route_target:
            export: "198.51.0.2:400"
            import_config: "198.51.0.5:200"
          vpn:
            id: "4:5"
          vnet:
            tag: 500
    state: overridden

# Task Output:
# ------------
#
# before:
#   - name: VRF2
#     description: This is a test VRF for merged state
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "2:3"
#     route_target:
#       export: "192.0.2.0:100"
#       import_config: "192.0.2.3:200"
#     vnet:
#       tag: 200
#     vpn:
#       id: "2:45
#   - name: VRF7
#     description: VRF7 description
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "7:8"
#     route_target:
#       export: "198.51.100.112:500"
#       import_config: "192.0.2.4:400"
#     vnet:
#       tag: 300
#     vpn:
#       id: "5:45"
#
# commands:
# - vrf definition VRF2
# - no description This is a test VRF for merged state
# - no ipv4 multicast multitopology
# - no ipv6 multicast multitopology
# - no rd 2:3
# - no route-target export 192.0.2.0:100
# - no route-target import 192.0.2.3:200
# - no vnet tag 200
# - no vpn id 2:45
# - vrf definition VRF7
# - no description VRF7 description
# - no ipv4 multicast multitopology
# - no ipv6 multicast multitopology
# - no rd 7:8
# - no route-target export 198.51.100.112:500
# - no route-target import 192.0.2.4:400
# - no vnet tag 300
# - no vpn id 5:45
# - vrf definition VRF6
# - description VRF6 description
# - ipv4 multicast multitopology
# - ipv6 multicast multitopology
# - rd 6:7
# - route-target export 198.51.0.2:400
# - route-target import 198.51.0.5:200
# - vnet tag 500
# - vpn id 4:5
#
# after:
#   - name: VRF2
#   - name: VRF6
#     description: VRF6 description
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "6:7"
#     route_target:
#       export: "198.51.0.2:400"
#       import_config: "198.51.0.5:200"
#     vnet:
#       tag: 500
#     vpn:
#       id: "4:5
#   - name: VRF7

# After state:
# ------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
#  vnet tag 500
#  description VRF6 description
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 6:7
#  vpn id 4:5
#  route-target export 198.51.0.2:400
#  route-target import 198.51.0.5:200
# vrf definition VRF7

# Using Deleted

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
#  vnet tag 500
#  description VRF6 description
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 6:7
#  vpn id 4:5
#  route-target export 198.51.0.2:400
#  route-target import 198.51.0.5:200
# vrf definition VRF7

- name: Delete the provided configuration when config is given
  cisco.ios.ios_vrf_global:
    config:
      vrfs:
        - name: VRF2
        - name: VRF6
        - name: VRF7
    state: deleted

# Task Output:
# ------------
#
# before:
#   - name: VRF2
#   - name: VRF6
#     description: VRF6 description
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "6:7"
#     route_target:
#       export: "198.51.0.2:400"
#       import_config: "198.51.0.5:200"
#     vnet:
#       tag: 500
#     vpn:
#       id: "4:5"
#   - name: VRF7
#
# commands:
# - vrf definition VRF2
# - vrf definition VRF6
# - no description VRF6 description
# - no ipv4 multicast multitopology
# - no ipv6 multicast multitopology
# - no rd 6:7
# - no route-target export 198.51.0.2:400
# - no route-target import 198.51.0.5:200
# - no vnet tag 500
# - no vpn id 4:5
# - vrf definition VRF7
#
# after:
#   - name: VRF2
#   - name: VRF6
#   - name: VRF7

# After state:
# -------------
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
# vrf definition VRF7

# Using Deleted with empty config

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
#  vnet tag 500
#  description VRF6 description
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 6:7
#  vpn id 4:5
#  route-target export 198.51.0.2:400
#  route-target import 198.51.0.5:200
# vrf definition VRF7

- name: Delete the provided configuration when config is empty
  cisco.ios.ios_vrf_global:
    config:
    state: deleted

# Task Output:
# ------------
#
# before:
#   - name: VRF2
#   - name: VRF6
#     description: VRF6 description
#     ipv4:
#       multicast:
#         multitopology: true
#     ipv6:
#       multicast:
#         multitopology: true
#     rd: "6:7"
#     route_target:
#       export: "198.51.0.2:400"
#       import_config: "198.51.0.5:200"
#     vnet:
#       tag: 500
#     vpn:
#       id: "4:5"
#   - name: VRF7

# commands:
# - vrf definition VRF2
# - vrf definition VRF6
# - no description VRF6 description
# - no ipv4 multicast multitopology
# - no ipv6 multicast multitopology
# - no rd 6:7
# - no route-target export 198.51.0.2:400
# - no route-target import 198.51.0.5:200
# - no vnet tag 500
# - no vpn id 4:5
# - vrf definition VRF7
#
# after:
#   - name: VRF2
#   - name: VRF6
#   - name: VRF7

# After state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
# vrf definition VRF7

# Using purged - would delete all the VRF definitions

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
# vrf definition VRF6
# vrf definition VRF7

- name: Purge all the configuration from the device
  cisco.ios.ios_vrf_global:
    state: purged

# Task Output:
# ------------
#
# before:
#   - name: VRF2
#   - name: VRF6
#   - name: VRF7
# commands:
# - no vrf definition VRF2
# - no vrf definition VRF6
# - no vrf definition VRF7
# after: {}

# After state:
# -------------
#
# admin#show running-config | section ^vrf

# Using Rendered

- name: Render provided configuration with device configuration
  cisco.ios.ios_vrf_global:
    config:
      vrfs:
        - name: VRF2
          description: This is a test VRF for merged state
          ipv4:
            multicast:
              multitopology: true
          ipv6:
            multicast:
              multitopology: true
          rd: "2:3"
          route_target:
            export: "192.0.2.0:100"
            import_config: "192.0.2.3:200"
          vpn:
            id: "2:45"
          vnet:
            tag: 200
    state: rendered

# Task Output:
# ------------
#
# rendered:
# - vrf definition VRF2
# - description This is a test VRF for merged state
# - ipv4 multicast multitopology
# - ipv6 multicast multitopology
# - rd 2:3
# - route-target export 192.0.2.0:100
# - route-target import 192.0.2.3:200
# - vnet tag 200
# - vpn id 2:45

# Using Gathered

# Before state:
# -------------
#
# admin#show running-config | section ^vrf
# vrf definition VRF2
#  vnet tag 200
#  description This is a test VRF for merged state
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 2:3
#  vpn id 2:45
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.3:200

- name: Gather existing running configuration
  cisco.ios.ios_vrf_global:
    config:
    state: gathered

# Task Output:
# ------------
#
# gathered:
#   vrfs:
#     - name: VRF2
#       description: This is a test VRF for merged state
#       ipv4:
#         multicast:
#           multitopology: true
#       ipv6:
#         multicast:
#           multitopology: true
#       rd: "2:3"
#       route_target:
#         export: "192.0.2.0:100"
#         import_config: "192.0.2.3:200"
#       vnet:
#         tag: 200
#       vpn:
#         id: "2:45"

# Using parsed

# File: parsed.cfg
# ----------------
#
# vrf definition test
#  vnet tag 34
#  description This is test VRF
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 192.0.2.0:300
#  vpn id 3:4
#  route-target export 192.0.2.0:100
#  route-target import 192.0.2.2:300
# vrf definition test2
#  vnet tag 35
#  description This is test VRF
#  ipv4 multicast multitopology
#  ipv6 multicast multitopology
#  rd 192.0.2.3:300

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

# Task Output:
# ------------
#
# parsed:
#   vrfs:
#     - name: test
#       description: This is test VRF
#       ipv4:
#         multicast:
#           multitopology: true
#       ipv6:
#         multicast:
#           multitopology: true
#       rd: "192.0.2.0:300"
#       route_target:
#         export: "192.0.2.0:100"
#         import_config: "192.0.2.2:300"
#       vnet:
#         tag: 34
#       vpn:
#         id: "3:4"
#     - name: test2
#       description: This is test VRF
#       ipv4:
#         multicast:
#           multitopology: true
#       ipv6:
#         multicast:
#           multitopology: true
#       rd: "192.0.2.3:300"
#       vnet:
#         tag: 35

返回值

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

描述

after

字典

模块执行后的结果配置。

返回:发生更改时

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

before

字典

模块执行之前的配置。

返回:statemergedreplacedoverriddendeletedpurged

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

commands

列表 / 元素=字符串

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

返回:statemergedreplacedoverriddendeletedpurged

示例: ["vrf definition test", "description This is a test VRF", "rd: 2:3"]

gathered

列表 / 元素=字符串

从远程设备收集的关于网络资源的事实,作为结构化数据。

返回:stategathered

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

已解析

列表 / 元素=字符串

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

返回:stateparsed

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

已渲染

列表 / 元素=字符串

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

返回:staterendered

示例: ["vrf definition management", "description This is a test VRF", "rd: 2:3", "route-target export 190.0.2.3:400", "route-target import 190.0.2.1:300"]

作者

  • Ruchi Pakhle (@Ruchip16)