| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright 2024 Red Hat |
| 4 |
# GNU General Public License v3.0+ |
| 5 |
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
""" |
| 8 |
The module file for ios_vrf_global |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
|
| 13 |
|
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = """ |
| 17 |
module: ios_vrf_global |
| 18 |
short_description: Resource module to configure global VRF definitions. |
| 19 |
description: This module provides declarative management of VRF definitions on Cisco IOS. |
| 20 |
version_added: 8.0.0 |
| 21 |
author: Ruchi Pakhle (@Ruchip16) |
| 22 |
notes: |
| 23 |
- Tested against Cisco IOS-XE version 17.3 on CML. |
| 24 |
- This module works with connection C(network_cli). |
| 25 |
See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html) |
| 26 |
- The module examples uses callback plugin (stdout_callback = yaml) to generate task |
| 27 |
output in yaml format. |
| 28 |
options: |
| 29 |
config: |
| 30 |
description: A dictionary containing device configurations for VRF, including a list of VRF definitions. |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
vrfs: |
| 34 |
description: List of VRF definitions. |
| 35 |
type: list |
| 36 |
elements: dict |
| 37 |
suboptions: |
| 38 |
name: |
| 39 |
description: Name of the VRF. |
| 40 |
type: str |
| 41 |
required: true |
| 42 |
description: |
| 43 |
description: VRF specific description |
| 44 |
type: str |
| 45 |
ipv4: |
| 46 |
description: VRF IPv4 configuration |
| 47 |
type: dict |
| 48 |
suboptions: |
| 49 |
multicast: |
| 50 |
description: IPv4 multicast configuration |
| 51 |
type: dict |
| 52 |
suboptions: |
| 53 |
multitopology: |
| 54 |
description: Enable multicast-specific topology |
| 55 |
type: bool |
| 56 |
ipv6: |
| 57 |
description: VRF IPv6 configuration |
| 58 |
type: dict |
| 59 |
suboptions: |
| 60 |
multicast: |
| 61 |
description: IPv6 multicast configuration |
| 62 |
type: dict |
| 63 |
suboptions: |
| 64 |
multitopology: |
| 65 |
description: Enable multicast-specific topology |
| 66 |
type: bool |
| 67 |
rd: |
| 68 |
description: Specify route distinguisher (RD). |
| 69 |
type: str |
| 70 |
route_target: |
| 71 |
description: Specify target VPN extended configurations. |
| 72 |
type: dict |
| 73 |
suboptions: |
| 74 |
export: |
| 75 |
description: |
| 76 |
- This option is DEPRECATED and is replaced with exports which |
| 77 |
accepts list as input. |
| 78 |
type: str |
| 79 |
exports: |
| 80 |
description: Export target-VPN configuration. |
| 81 |
type: list |
| 82 |
elements: str |
| 83 |
import_config: |
| 84 |
description: |
| 85 |
- This option is DEPRECATED and is replaced with imports which |
| 86 |
accepts list as input. |
| 87 |
type: str |
| 88 |
imports: |
| 89 |
description: Import target-VPN configuration. |
| 90 |
type: list |
| 91 |
elements: str |
| 92 |
both: |
| 93 |
description: |
| 94 |
- This option is DEPRECATED and is replaced with both_options which |
| 95 |
accepts list as input. |
| 96 |
type: str |
| 97 |
both_options: |
| 98 |
description: Both export and import target-VPN configuration. |
| 99 |
type: list |
| 100 |
elements: str |
| 101 |
vnet: |
| 102 |
description: Virtual networking configuration. |
| 103 |
type: dict |
| 104 |
suboptions: |
| 105 |
tag: |
| 106 |
description: Identifier used to tag packets associated with this VNET. |
| 107 |
type: int |
| 108 |
vpn: |
| 109 |
description: Configure vpn-id for the VRF as specified in RFC 2685. |
| 110 |
type: dict |
| 111 |
suboptions: |
| 112 |
id: |
| 113 |
description: Configure vpn-id in RFC 2685 format. |
| 114 |
type: str |
| 115 |
running_config: |
| 116 |
description: |
| 117 |
- This option is used only with state I(parsed). |
| 118 |
- The value of this option should be the output received from the IOS device by |
| 119 |
executing the command B(show running-config | section ^vrf). |
| 120 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 121 |
transforms it into Ansible structured data as per the resource module's argspec |
| 122 |
and the value is then returned in the I(parsed) key within the result. |
| 123 |
type: str |
| 124 |
state: |
| 125 |
choices: [parsed, gathered, deleted, merged, replaced, rendered, overridden, purged] |
| 126 |
default: merged |
| 127 |
description: |
| 128 |
- The state the configuration should be left in |
| 129 |
- The states I(rendered), I(gathered) and I(parsed) does not perform any change |
| 130 |
on the device. |
| 131 |
- The state I(rendered) will transform the configuration in C(config) option to |
| 132 |
platform specific CLI commands which will be returned in the I(rendered) key |
| 133 |
within the result. For state I(rendered) active connection to remote host is |
| 134 |
not required. |
| 135 |
- The state I(gathered) will fetch the running configuration from device and transform |
| 136 |
it into structured data in the format as per the resource module argspec and |
| 137 |
the value is returned in the I(gathered) key within the result. |
| 138 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 139 |
transforms it into JSON format as per the module parameters and the |
| 140 |
value is returned in the I(parsed) key within the result. The value of C(running_config) |
| 141 |
option should be the same format as the output of command I(show running-config | section vrf). |
| 142 |
connection to remote host is not required. |
| 143 |
- The state I(deleted) only removes the VRF attributes that this module |
| 144 |
manages and does not negate the VRF completely. Thereby, preserving |
| 145 |
address-family related configurations under VRF context. |
| 146 |
- The state I(purged) removes all the VRF definitions from the |
| 147 |
target device. Use caution with this state. |
| 148 |
- Refer to examples for more details. |
| 149 |
type: str |
| 150 |
""" |
| 151 |
|
| 152 |
EXAMPLES = """ |
| 153 |
# Using merged |
| 154 |
|
| 155 |
# Before state: |
| 156 |
# ------------- |
| 157 |
# |
| 158 |
# admin#show running-config | section ^vrf |
| 159 |
|
| 160 |
- name: Merge provided configuration with device configuration |
| 161 |
cisco.ios.ios_vrf_global: |
| 162 |
config: |
| 163 |
vrfs: |
| 164 |
- name: VRF2 |
| 165 |
description: This is a test VRF for merged state |
| 166 |
ipv4: |
| 167 |
multicast: |
| 168 |
multitopology: true |
| 169 |
ipv6: |
| 170 |
multicast: |
| 171 |
multitopology: true |
| 172 |
rd: "2:3" |
| 173 |
route_target: |
| 174 |
exports: "192.0.2.0:100" |
| 175 |
imports: "192.0.2.3:200" |
| 176 |
vpn: |
| 177 |
id: "2:45" |
| 178 |
vnet: |
| 179 |
tag: 200 |
| 180 |
state: merged |
| 181 |
|
| 182 |
# Task output |
| 183 |
# ------------- |
| 184 |
# |
| 185 |
# before: {} |
| 186 |
# |
| 187 |
# commands: |
| 188 |
# - vrf definition VRF2 |
| 189 |
# - description This is a test VRF for merged state |
| 190 |
# - ipv4 multicast multitopology |
| 191 |
# - ipv6 multicast multitopology |
| 192 |
# - rd 2:3 |
| 193 |
# - route-target export 192.0.2.0:100 |
| 194 |
# - route-target import 192.0.2.3:200 |
| 195 |
# - vnet tag 200 |
| 196 |
# - vpn id 2:45 |
| 197 |
# |
| 198 |
# after: |
| 199 |
# - name: VRF2 |
| 200 |
# description: This is a test VRF for merged state |
| 201 |
# ipv4: |
| 202 |
# multicast: |
| 203 |
# multitopology: true |
| 204 |
# ipv6: |
| 205 |
# multicast: |
| 206 |
# multitopology: true |
| 207 |
# rd: "2:3" |
| 208 |
# route_target: |
| 209 |
# exports: "192.0.2.0:100" |
| 210 |
# imports: "192.0.2.3:200" |
| 211 |
# vnet: |
| 212 |
# tag: 200 |
| 213 |
# vpn: |
| 214 |
# id: "2:45" |
| 215 |
|
| 216 |
# After state: |
| 217 |
# ------------- |
| 218 |
# |
| 219 |
# admin#show running-config | section ^vrf |
| 220 |
# vrf definition VRF2 |
| 221 |
# vnet tag 200 |
| 222 |
# description This is a test VRF for merged state |
| 223 |
# ipv4 multicast multitopology |
| 224 |
# ipv6 multicast multitopology |
| 225 |
# rd 2:3 |
| 226 |
# vpn id 2:45 |
| 227 |
# route-target export 192.0.2.0:100 |
| 228 |
# route-target import 192.0.2.3:200 |
| 229 |
|
| 230 |
# Using replaced |
| 231 |
|
| 232 |
# Before state: |
| 233 |
# ------------- |
| 234 |
# |
| 235 |
# admin#show running-config | section ^vrf |
| 236 |
# vrf definition VRF2 |
| 237 |
# vnet tag 200 |
| 238 |
# description This is a test VRF for merged state |
| 239 |
# ipv4 multicast multitopology |
| 240 |
# ipv6 multicast multitopology |
| 241 |
# rd 2:3 |
| 242 |
# vpn id 2:45 |
| 243 |
# route-target export 192.0.2.0:100 |
| 244 |
# route-target import 192.0.2.3:200 |
| 245 |
|
| 246 |
- name: Replace the provided configuration with the existing running configuration |
| 247 |
cisco.ios.ios_vrf_global: |
| 248 |
config: |
| 249 |
vrfs: |
| 250 |
- name: VRF7 |
| 251 |
description: VRF7 description |
| 252 |
ipv4: |
| 253 |
multicast: |
| 254 |
multitopology: true |
| 255 |
ipv6: |
| 256 |
multicast: |
| 257 |
multitopology: true |
| 258 |
rd: "7:8" |
| 259 |
route_target: |
| 260 |
exports: "198.51.100.112:500" |
| 261 |
imports: "192.0.2.4:400" |
| 262 |
vpn: |
| 263 |
id: "5:45" |
| 264 |
vnet: |
| 265 |
tag: 300 |
| 266 |
state: replaced |
| 267 |
|
| 268 |
# Task Output: |
| 269 |
# ------------ |
| 270 |
# |
| 271 |
# before: |
| 272 |
# - name: VRF2 |
| 273 |
# description: This is a test VRF for merged state |
| 274 |
# ipv4: |
| 275 |
# multicast: |
| 276 |
# multitopology: true |
| 277 |
# ipv6: |
| 278 |
# multicast: |
| 279 |
# multitopology: true |
| 280 |
# rd: "2:3" |
| 281 |
# route_target: |
| 282 |
# exports: "192.0.2.0:100" |
| 283 |
# imports: "192.0.2.3:200" |
| 284 |
# vnet: |
| 285 |
# tag: 200 |
| 286 |
# vpn: |
| 287 |
# id: "2:45 |
| 288 |
# |
| 289 |
# commands: |
| 290 |
# - vrf definition VRF7 |
| 291 |
# - description VRF7 description |
| 292 |
# - ipv4 multicast multitopology |
| 293 |
# - ipv6 multicast multitopology |
| 294 |
# - rd 7:8 |
| 295 |
# - route-target export 198.51.100.112:500 |
| 296 |
# - route-target import 192.0.2.4:400 |
| 297 |
# - vnet tag 300 |
| 298 |
# - vpn id 5:45 |
| 299 |
# |
| 300 |
# after: |
| 301 |
# - name: VRF2 |
| 302 |
# description: This is a test VRF for merged state |
| 303 |
# ipv4: |
| 304 |
# multicast: |
| 305 |
# multitopology: true |
| 306 |
# ipv6: |
| 307 |
# multicast: |
| 308 |
# multitopology: true |
| 309 |
# rd: "2:3" |
| 310 |
# route_target: |
| 311 |
# exports: "192.0.2.0:100" |
| 312 |
# imports: "192.0.2.3:200" |
| 313 |
# vnet: |
| 314 |
# tag: 200 |
| 315 |
# vpn: |
| 316 |
# id: "2:45 |
| 317 |
# - name: VRF7 |
| 318 |
# description: VRF7 description |
| 319 |
# ipv4: |
| 320 |
# multicast: |
| 321 |
# multitopology: true |
| 322 |
# ipv6: |
| 323 |
# multicast: |
| 324 |
# multitopology: true |
| 325 |
# rd: "7:8" |
| 326 |
# route_target: |
| 327 |
# exports: "198.51.100.112:500" |
| 328 |
# imports: "192.0.2.4:400" |
| 329 |
# vnet: |
| 330 |
# tag: 300 |
| 331 |
# vpn: |
| 332 |
# id: "5:45" |
| 333 |
# |
| 334 |
# After state: |
| 335 |
# ------------- |
| 336 |
# |
| 337 |
# admin#show running-config | section ^vrf |
| 338 |
# vrf definition VRF2 |
| 339 |
# vnet tag 200 |
| 340 |
# description This is a test VRF for merged state |
| 341 |
# ipv4 multicast multitopology |
| 342 |
# ipv6 multicast multitopology |
| 343 |
# rd 2:3 |
| 344 |
# vpn id 2:45 |
| 345 |
# route-target export 192.0.2.0:100 |
| 346 |
# route-target import 192.0.2.3:200 |
| 347 |
# vrf definition VRF7 |
| 348 |
# vnet tag 300 |
| 349 |
# description VRF7 description |
| 350 |
# ipv4 multicast multitopology |
| 351 |
# ipv6 multicast multitopology |
| 352 |
# rd 7:8 |
| 353 |
# route-target export 198.51.100.112:500 |
| 354 |
# route-target import 192.0.2.4:400 |
| 355 |
# vpn id 5:45 |
| 356 |
|
| 357 |
# Using Overridden |
| 358 |
|
| 359 |
# Before state: |
| 360 |
# ------------- |
| 361 |
# |
| 362 |
# admin#show running-config | section ^vrf |
| 363 |
# vrf definition VRF2 |
| 364 |
# vnet tag 200 |
| 365 |
# description This is a test VRF for merged state |
| 366 |
# ipv4 multicast multitopology |
| 367 |
# ipv6 multicast multitopology |
| 368 |
# rd 2:3 |
| 369 |
# vpn id 2:45 |
| 370 |
# route-target export 192.0.2.0:100 |
| 371 |
# route-target import 192.0.2.3:200 |
| 372 |
# vrf definition VRF7 |
| 373 |
# vnet tag 300 |
| 374 |
# description VRF7 description |
| 375 |
# ipv4 multicast multitopology |
| 376 |
# ipv6 multicast multitopology |
| 377 |
# rd 7:8 |
| 378 |
# route-target export 198.51.100.112:500 |
| 379 |
# route-target import 192.0.2.4:400 |
| 380 |
# vpn id 5:45 |
| 381 |
|
| 382 |
- name: Override the provided configuration with the existing running configuration |
| 383 |
cisco.ios.ios_vrf_global: |
| 384 |
config: |
| 385 |
vrfs: |
| 386 |
- name: VRF6 |
| 387 |
description: VRF6 description |
| 388 |
ipv4: |
| 389 |
multicast: |
| 390 |
multitopology: true |
| 391 |
ipv6: |
| 392 |
multicast: |
| 393 |
multitopology: true |
| 394 |
rd: "6:7" |
| 395 |
route_target: |
| 396 |
exports: "198.51.0.2:400" |
| 397 |
imports: "198.51.0.5:200" |
| 398 |
vpn: |
| 399 |
id: "4:5" |
| 400 |
vnet: |
| 401 |
tag: 500 |
| 402 |
state: overridden |
| 403 |
|
| 404 |
# Task Output: |
| 405 |
# ------------ |
| 406 |
# |
| 407 |
# before: |
| 408 |
# - name: VRF2 |
| 409 |
# description: This is a test VRF for merged state |
| 410 |
# ipv4: |
| 411 |
# multicast: |
| 412 |
# multitopology: true |
| 413 |
# ipv6: |
| 414 |
# multicast: |
| 415 |
# multitopology: true |
| 416 |
# rd: "2:3" |
| 417 |
# route_target: |
| 418 |
# exports: "192.0.2.0:100" |
| 419 |
# imports: "192.0.2.3:200" |
| 420 |
# vnet: |
| 421 |
# tag: 200 |
| 422 |
# vpn: |
| 423 |
# id: "2:45 |
| 424 |
# - name: VRF7 |
| 425 |
# description: VRF7 description |
| 426 |
# ipv4: |
| 427 |
# multicast: |
| 428 |
# multitopology: true |
| 429 |
# ipv6: |
| 430 |
# multicast: |
| 431 |
# multitopology: true |
| 432 |
# rd: "7:8" |
| 433 |
# route_target: |
| 434 |
# exports: "198.51.100.112:500" |
| 435 |
# imports: "192.0.2.4:400" |
| 436 |
# vnet: |
| 437 |
# tag: 300 |
| 438 |
# vpn: |
| 439 |
# id: "5:45" |
| 440 |
# |
| 441 |
# commands: |
| 442 |
# - vrf definition VRF2 |
| 443 |
# - no description This is a test VRF for merged state |
| 444 |
# - no ipv4 multicast multitopology |
| 445 |
# - no ipv6 multicast multitopology |
| 446 |
# - no rd 2:3 |
| 447 |
# - no route-target export 192.0.2.0:100 |
| 448 |
# - no route-target import 192.0.2.3:200 |
| 449 |
# - no vnet tag 200 |
| 450 |
# - no vpn id 2:45 |
| 451 |
# - vrf definition VRF7 |
| 452 |
# - no description VRF7 description |
| 453 |
# - no ipv4 multicast multitopology |
| 454 |
# - no ipv6 multicast multitopology |
| 455 |
# - no rd 7:8 |
| 456 |
# - no route-target export 198.51.100.112:500 |
| 457 |
# - no route-target import 192.0.2.4:400 |
| 458 |
# - no vnet tag 300 |
| 459 |
# - no vpn id 5:45 |
| 460 |
# - vrf definition VRF6 |
| 461 |
# - description VRF6 description |
| 462 |
# - ipv4 multicast multitopology |
| 463 |
# - ipv6 multicast multitopology |
| 464 |
# - rd 6:7 |
| 465 |
# - route-target export 198.51.0.2:400 |
| 466 |
# - route-target import 198.51.0.5:200 |
| 467 |
# - vnet tag 500 |
| 468 |
# - vpn id 4:5 |
| 469 |
# |
| 470 |
# after: |
| 471 |
# - name: VRF2 |
| 472 |
# - name: VRF6 |
| 473 |
# description: VRF6 description |
| 474 |
# ipv4: |
| 475 |
# multicast: |
| 476 |
# multitopology: true |
| 477 |
# ipv6: |
| 478 |
# multicast: |
| 479 |
# multitopology: true |
| 480 |
# rd: "6:7" |
| 481 |
# route_target: |
| 482 |
# exports: "198.51.0.2:400" |
| 483 |
# imports: "198.51.0.5:200" |
| 484 |
# vnet: |
| 485 |
# tag: 500 |
| 486 |
# vpn: |
| 487 |
# id: "4:5 |
| 488 |
# - name: VRF7 |
| 489 |
|
| 490 |
# After state: |
| 491 |
# ------------ |
| 492 |
# |
| 493 |
# admin#show running-config | section ^vrf |
| 494 |
# vrf definition VRF2 |
| 495 |
# vrf definition VRF6 |
| 496 |
# vnet tag 500 |
| 497 |
# description VRF6 description |
| 498 |
# ipv4 multicast multitopology |
| 499 |
# ipv6 multicast multitopology |
| 500 |
# rd 6:7 |
| 501 |
# vpn id 4:5 |
| 502 |
# route-target export 198.51.0.2:400 |
| 503 |
# route-target import 198.51.0.5:200 |
| 504 |
# vrf definition VRF7 |
| 505 |
|
| 506 |
# Using Deleted |
| 507 |
|
| 508 |
# Before state: |
| 509 |
# ------------- |
| 510 |
# |
| 511 |
# admin#show running-config | section ^vrf |
| 512 |
# vrf definition VRF2 |
| 513 |
# vrf definition VRF6 |
| 514 |
# vnet tag 500 |
| 515 |
# description VRF6 description |
| 516 |
# ipv4 multicast multitopology |
| 517 |
# ipv6 multicast multitopology |
| 518 |
# rd 6:7 |
| 519 |
# vpn id 4:5 |
| 520 |
# route-target export 198.51.0.2:400 |
| 521 |
# route-target import 198.51.0.5:200 |
| 522 |
# vrf definition VRF7 |
| 523 |
|
| 524 |
- name: Delete the provided configuration when config is given |
| 525 |
cisco.ios.ios_vrf_global: |
| 526 |
config: |
| 527 |
vrfs: |
| 528 |
- name: VRF2 |
| 529 |
- name: VRF6 |
| 530 |
- name: VRF7 |
| 531 |
state: deleted |
| 532 |
|
| 533 |
# Task Output: |
| 534 |
# ------------ |
| 535 |
# |
| 536 |
# before: |
| 537 |
# - name: VRF2 |
| 538 |
# - name: VRF6 |
| 539 |
# description: VRF6 description |
| 540 |
# ipv4: |
| 541 |
# multicast: |
| 542 |
# multitopology: true |
| 543 |
# ipv6: |
| 544 |
# multicast: |
| 545 |
# multitopology: true |
| 546 |
# rd: "6:7" |
| 547 |
# route_target: |
| 548 |
# exports: "198.51.0.2:400" |
| 549 |
# imports: "198.51.0.5:200" |
| 550 |
# vnet: |
| 551 |
# tag: 500 |
| 552 |
# vpn: |
| 553 |
# id: "4:5" |
| 554 |
# - name: VRF7 |
| 555 |
# |
| 556 |
# commands: |
| 557 |
# - vrf definition VRF2 |
| 558 |
# - vrf definition VRF6 |
| 559 |
# - no description VRF6 description |
| 560 |
# - no ipv4 multicast multitopology |
| 561 |
# - no ipv6 multicast multitopology |
| 562 |
# - no rd 6:7 |
| 563 |
# - no route-target export 198.51.0.2:400 |
| 564 |
# - no route-target import 198.51.0.5:200 |
| 565 |
# - no vnet tag 500 |
| 566 |
# - no vpn id 4:5 |
| 567 |
# - vrf definition VRF7 |
| 568 |
# |
| 569 |
# after: |
| 570 |
# - name: VRF2 |
| 571 |
# - name: VRF6 |
| 572 |
# - name: VRF7 |
| 573 |
|
| 574 |
# After state: |
| 575 |
# ------------- |
| 576 |
# admin#show running-config | section ^vrf |
| 577 |
# vrf definition VRF2 |
| 578 |
# vrf definition VRF6 |
| 579 |
# vrf definition VRF7 |
| 580 |
|
| 581 |
# Using Deleted with empty config |
| 582 |
|
| 583 |
# Before state: |
| 584 |
# ------------- |
| 585 |
# |
| 586 |
# admin#show running-config | section ^vrf |
| 587 |
# vrf definition VRF2 |
| 588 |
# vrf definition VRF6 |
| 589 |
# vnet tag 500 |
| 590 |
# description VRF6 description |
| 591 |
# ipv4 multicast multitopology |
| 592 |
# ipv6 multicast multitopology |
| 593 |
# rd 6:7 |
| 594 |
# vpn id 4:5 |
| 595 |
# route-target export 198.51.0.2:400 |
| 596 |
# route-target import 198.51.0.5:200 |
| 597 |
# vrf definition VRF7 |
| 598 |
|
| 599 |
- name: Delete the provided configuration when config is empty |
| 600 |
cisco.ios.ios_vrf_global: |
| 601 |
config: |
| 602 |
state: deleted |
| 603 |
|
| 604 |
# Task Output: |
| 605 |
# ------------ |
| 606 |
# |
| 607 |
# before: |
| 608 |
# - name: VRF2 |
| 609 |
# - name: VRF6 |
| 610 |
# description: VRF6 description |
| 611 |
# ipv4: |
| 612 |
# multicast: |
| 613 |
# multitopology: true |
| 614 |
# ipv6: |
| 615 |
# multicast: |
| 616 |
# multitopology: true |
| 617 |
# rd: "6:7" |
| 618 |
# route_target: |
| 619 |
# exports: "198.51.0.2:400" |
| 620 |
# imports: "198.51.0.5:200" |
| 621 |
# vnet: |
| 622 |
# tag: 500 |
| 623 |
# vpn: |
| 624 |
# id: "4:5" |
| 625 |
# - name: VRF7 |
| 626 |
|
| 627 |
# commands: |
| 628 |
# - vrf definition VRF2 |
| 629 |
# - vrf definition VRF6 |
| 630 |
# - no description VRF6 description |
| 631 |
# - no ipv4 multicast multitopology |
| 632 |
# - no ipv6 multicast multitopology |
| 633 |
# - no rd 6:7 |
| 634 |
# - no route-target export 198.51.0.2:400 |
| 635 |
# - no route-target import 198.51.0.5:200 |
| 636 |
# - no vnet tag 500 |
| 637 |
# - no vpn id 4:5 |
| 638 |
# - vrf definition VRF7 |
| 639 |
# |
| 640 |
# after: |
| 641 |
# - name: VRF2 |
| 642 |
# - name: VRF6 |
| 643 |
# - name: VRF7 |
| 644 |
|
| 645 |
# After state: |
| 646 |
# ------------- |
| 647 |
# |
| 648 |
# admin#show running-config | section ^vrf |
| 649 |
# vrf definition VRF2 |
| 650 |
# vrf definition VRF6 |
| 651 |
# vrf definition VRF7 |
| 652 |
|
| 653 |
# Using purged - would delete all the VRF definitions |
| 654 |
|
| 655 |
# Before state: |
| 656 |
# ------------- |
| 657 |
# |
| 658 |
# admin#show running-config | section ^vrf |
| 659 |
# vrf definition VRF2 |
| 660 |
# vrf definition VRF6 |
| 661 |
# vrf definition VRF7 |
| 662 |
|
| 663 |
- name: Purge all the configuration from the device |
| 664 |
cisco.ios.ios_vrf_global: |
| 665 |
state: purged |
| 666 |
|
| 667 |
# Task Output: |
| 668 |
# ------------ |
| 669 |
# |
| 670 |
# before: |
| 671 |
# - name: VRF2 |
| 672 |
# - name: VRF6 |
| 673 |
# - name: VRF7 |
| 674 |
# commands: |
| 675 |
# - no vrf definition VRF2 |
| 676 |
# - no vrf definition VRF6 |
| 677 |
# - no vrf definition VRF7 |
| 678 |
# after: {} |
| 679 |
|
| 680 |
# After state: |
| 681 |
# ------------- |
| 682 |
# |
| 683 |
# admin#show running-config | section ^vrf |
| 684 |
|
| 685 |
# Using Rendered |
| 686 |
|
| 687 |
- name: Render provided configuration with device configuration |
| 688 |
cisco.ios.ios_vrf_global: |
| 689 |
config: |
| 690 |
vrfs: |
| 691 |
- name: VRF2 |
| 692 |
description: This is a test VRF for merged state |
| 693 |
ipv4: |
| 694 |
multicast: |
| 695 |
multitopology: true |
| 696 |
ipv6: |
| 697 |
multicast: |
| 698 |
multitopology: true |
| 699 |
rd: "2:3" |
| 700 |
route_target: |
| 701 |
exports: "192.0.2.0:100" |
| 702 |
imports: "192.0.2.3:200" |
| 703 |
vpn: |
| 704 |
id: "2:45" |
| 705 |
vnet: |
| 706 |
tag: 200 |
| 707 |
state: rendered |
| 708 |
|
| 709 |
# Task Output: |
| 710 |
# ------------ |
| 711 |
# |
| 712 |
# rendered: |
| 713 |
# - vrf definition VRF2 |
| 714 |
# - description This is a test VRF for merged state |
| 715 |
# - ipv4 multicast multitopology |
| 716 |
# - ipv6 multicast multitopology |
| 717 |
# - rd 2:3 |
| 718 |
# - route-target export 192.0.2.0:100 |
| 719 |
# - route-target import 192.0.2.3:200 |
| 720 |
# - vnet tag 200 |
| 721 |
# - vpn id 2:45 |
| 722 |
|
| 723 |
# Using Gathered |
| 724 |
|
| 725 |
# Before state: |
| 726 |
# ------------- |
| 727 |
# |
| 728 |
# admin#show running-config | section ^vrf |
| 729 |
# vrf definition VRF2 |
| 730 |
# vnet tag 200 |
| 731 |
# description This is a test VRF for merged state |
| 732 |
# ipv4 multicast multitopology |
| 733 |
# ipv6 multicast multitopology |
| 734 |
# rd 2:3 |
| 735 |
# vpn id 2:45 |
| 736 |
# route-target export 192.0.2.0:100 |
| 737 |
# route-target import 192.0.2.3:200 |
| 738 |
|
| 739 |
- name: Gather existing running configuration |
| 740 |
cisco.ios.ios_vrf_global: |
| 741 |
config: |
| 742 |
state: gathered |
| 743 |
|
| 744 |
# Task Output: |
| 745 |
# ------------ |
| 746 |
# |
| 747 |
# gathered: |
| 748 |
# vrfs: |
| 749 |
# - name: VRF2 |
| 750 |
# description: This is a test VRF for merged state |
| 751 |
# ipv4: |
| 752 |
# multicast: |
| 753 |
# multitopology: true |
| 754 |
# ipv6: |
| 755 |
# multicast: |
| 756 |
# multitopology: true |
| 757 |
# rd: "2:3" |
| 758 |
# route_target: |
| 759 |
# exports: "192.0.2.0:100" |
| 760 |
# imports: "192.0.2.3:200" |
| 761 |
# vnet: |
| 762 |
# tag: 200 |
| 763 |
# vpn: |
| 764 |
# id: "2:45" |
| 765 |
|
| 766 |
# Using parsed |
| 767 |
|
| 768 |
# File: parsed.cfg |
| 769 |
# ---------------- |
| 770 |
# |
| 771 |
# vrf definition test |
| 772 |
# vnet tag 34 |
| 773 |
# description This is test VRF |
| 774 |
# ipv4 multicast multitopology |
| 775 |
# ipv6 multicast multitopology |
| 776 |
# rd 192.0.2.0:300 |
| 777 |
# vpn id 3:4 |
| 778 |
# route-target export 192.0.2.0:100 |
| 779 |
# route-target import 192.0.2.2:300 |
| 780 |
# vrf definition test2 |
| 781 |
# vnet tag 35 |
| 782 |
# description This is test VRF |
| 783 |
# ipv4 multicast multitopology |
| 784 |
# ipv6 multicast multitopology |
| 785 |
# rd 192.0.2.3:300 |
| 786 |
|
| 787 |
- name: Parse the provided configuration |
| 788 |
cisco.ios.ios_vrf_global: |
| 789 |
running_config: "{{ lookup('file', 'parsed.cfg') }}" |
| 790 |
state: parsed |
| 791 |
|
| 792 |
# Task Output: |
| 793 |
# ------------ |
| 794 |
# |
| 795 |
# parsed: |
| 796 |
# vrfs: |
| 797 |
# - name: test |
| 798 |
# description: This is test VRF |
| 799 |
# ipv4: |
| 800 |
# multicast: |
| 801 |
# multitopology: true |
| 802 |
# ipv6: |
| 803 |
# multicast: |
| 804 |
# multitopology: true |
| 805 |
# rd: "192.0.2.0:300" |
| 806 |
# route_target: |
| 807 |
# exports: "192.0.2.0:100" |
| 808 |
# imports: "192.0.2.2:300" |
| 809 |
# vnet: |
| 810 |
# tag: 34 |
| 811 |
# vpn: |
| 812 |
# id: "3:4" |
| 813 |
# - name: test2 |
| 814 |
# description: This is test VRF |
| 815 |
# ipv4: |
| 816 |
# multicast: |
| 817 |
# multitopology: true |
| 818 |
# ipv6: |
| 819 |
# multicast: |
| 820 |
# multitopology: true |
| 821 |
# rd: "192.0.2.3:300" |
| 822 |
# vnet: |
| 823 |
# tag: 35 |
| 824 |
""" |
| 825 |
|
| 826 |
RETURN = """ |
| 827 |
before: |
| 828 |
description: The configuration prior to the module execution. |
| 829 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 830 |
type: dict |
| 831 |
sample: > |
| 832 |
This output will always be in the same format as the |
| 833 |
module argspec. |
| 834 |
after: |
| 835 |
description: The resulting configuration after module execution. |
| 836 |
returned: when changed |
| 837 |
type: dict |
| 838 |
sample: > |
| 839 |
This output will always be in the same format as the |
| 840 |
module argspec. |
| 841 |
commands: |
| 842 |
description: The set of commands pushed to the remote device. |
| 843 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 844 |
type: list |
| 845 |
sample: |
| 846 |
- "vrf definition test" |
| 847 |
- "description This is a test VRF" |
| 848 |
- "rd: 2:3" |
| 849 |
rendered: |
| 850 |
description: The provided configuration in the task rendered in device-native format (offline). |
| 851 |
returned: when I(state) is C(rendered) |
| 852 |
type: list |
| 853 |
sample: |
| 854 |
- "vrf definition management" |
| 855 |
- "description This is a test VRF" |
| 856 |
- "rd: 2:3" |
| 857 |
- "route-target export 190.0.2.3:400" |
| 858 |
- "route-target import 190.0.2.1:300" |
| 859 |
gathered: |
| 860 |
description: Facts about the network resource gathered from the remote device as structured data. |
| 861 |
returned: when I(state) is C(gathered) |
| 862 |
type: list |
| 863 |
sample: > |
| 864 |
This output will always be in the same format as the |
| 865 |
module argspec. |
| 866 |
parsed: |
| 867 |
description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. |
| 868 |
returned: when I(state) is C(parsed) |
| 869 |
type: list |
| 870 |
sample: > |
| 871 |
This output will always be in the same format as the |
| 872 |
module argspec. |
| 873 |
""" |
| 874 |
|
| 875 |
|
| 876 |
from ansible.module_utils.basic import AnsibleModule |
| 877 |
|
| 878 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vrf_global.vrf_global import ( |
| 879 |
Vrf_globalArgs, |
| 880 |
) |
| 881 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vrf_global.vrf_global import ( |
| 882 |
Vrf_global, |
| 883 |
) |
| 884 |
|
| 885 |
|
| 886 |
def main(): |
| 887 |
""" |
| 888 |
Main entry point for module execution |
| 889 |
|
| 890 |
:returns: the result form module invocation |
| 891 |
""" |
| 892 |
module = AnsibleModule( |
| 893 |
argument_spec=Vrf_globalArgs.argument_spec, |
| 894 |
mutually_exclusive=[["config", "running_config"]], |
| 895 |
required_if=[ |
| 896 |
["state", "merged", ["config"]], |
| 897 |
["state", "replaced", ["config"]], |
| 898 |
["state", "overridden", ["config"]], |
| 899 |
["state", "rendered", ["config"]], |
| 900 |
["state", "parsed", ["running_config"]], |
| 901 |
], |
| 902 |
supports_check_mode=True, |
| 903 |
) |
| 904 |
|
| 905 |
result = Vrf_global(module).execute_module() |
| 906 |
module.exit_json(**result) |
| 907 |
|
| 908 |
|
| 909 |
if __name__ == "__main__": |
| 910 |
main() |