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