| 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_address_family |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
|
| 13 |
|
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = """ |
| 17 |
module: ios_vrf_address_family |
| 18 |
short_description: Resource module to configure VRF definitions. |
| 19 |
description: This module provides declarative management of VRF definitions on Cisco IOS. |
| 20 |
version_added: 7.0.0 |
| 21 |
author: Ruchi Pakhle (@Ruchip16) |
| 22 |
notes: |
| 23 |
- Tested against Cisco IOSXE 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 |
options: |
| 27 |
config: |
| 28 |
description: A list of device configurations for VRF. |
| 29 |
type: list |
| 30 |
elements: dict |
| 31 |
suboptions: |
| 32 |
name: |
| 33 |
description: Name of the VRF. |
| 34 |
type: str |
| 35 |
required: true |
| 36 |
address_families: |
| 37 |
description: Enable address family and enter its config mode - AFI/SAFI configuration |
| 38 |
type: list |
| 39 |
elements: dict |
| 40 |
suboptions: |
| 41 |
afi: |
| 42 |
description: Address Family Identifier (AFI) |
| 43 |
type: str |
| 44 |
choices: ['ipv4', 'ipv6'] |
| 45 |
safi: |
| 46 |
description: Address Family modifier |
| 47 |
type: str |
| 48 |
choices: ['multicast', 'unicast'] |
| 49 |
bgp: &bgp01 |
| 50 |
description: Commands pertaining to BGP configuration. |
| 51 |
type: dict |
| 52 |
suboptions: |
| 53 |
next_hop: |
| 54 |
description: Next-hop for the routes of a VRF in the backbone. |
| 55 |
type: dict |
| 56 |
suboptions: |
| 57 |
loopback: |
| 58 |
description: Loopback interface for next-hop |
| 59 |
type: int |
| 60 |
export: &export |
| 61 |
description: VRF export |
| 62 |
type: dict |
| 63 |
suboptions: |
| 64 |
map: |
| 65 |
description: Route-map name |
| 66 |
type: str |
| 67 |
ipv4: |
| 68 |
description: Address family based VRF export |
| 69 |
type: dict |
| 70 |
suboptions: |
| 71 |
multicast: |
| 72 |
description: Export prefixes to IPv4 Multicast table |
| 73 |
type: dict |
| 74 |
suboptions: |
| 75 |
prefix: |
| 76 |
description: Upper limit on export prefixes without hogging memory |
| 77 |
type: int |
| 78 |
map: |
| 79 |
description: Route-map name |
| 80 |
type: str |
| 81 |
unicast: |
| 82 |
description: Export prefixes to IPv4 Unicast table |
| 83 |
type: dict |
| 84 |
suboptions: |
| 85 |
prefix: |
| 86 |
description: Upper limit on export prefixes without hogging memory |
| 87 |
type: int |
| 88 |
map: |
| 89 |
description: Route-map name |
| 90 |
type: str |
| 91 |
allow_evpn: |
| 92 |
description: Allow EVPN routes into global table |
| 93 |
type: bool |
| 94 |
import_config: &import01 |
| 95 |
description: VRF import |
| 96 |
type: dict |
| 97 |
suboptions: |
| 98 |
map: |
| 99 |
description: Route-map name |
| 100 |
type: str |
| 101 |
ipv4: |
| 102 |
description: Address family based VRF import |
| 103 |
type: dict |
| 104 |
suboptions: |
| 105 |
multicast: |
| 106 |
description: Import prefixes from IPv4 Multicast table |
| 107 |
type: dict |
| 108 |
suboptions: |
| 109 |
prefix: |
| 110 |
description: Upper limit on import prefixes without hogging memory |
| 111 |
type: int |
| 112 |
map: |
| 113 |
description: Route-map name |
| 114 |
type: str |
| 115 |
unicast: |
| 116 |
description: Import prefixes from IPv4 Unicast table |
| 117 |
type: dict |
| 118 |
suboptions: |
| 119 |
limit: |
| 120 |
description: Upper limit on import prefixes without hogging memory |
| 121 |
type: int |
| 122 |
map: |
| 123 |
description: Route-map based VRF import |
| 124 |
type: str |
| 125 |
allow_evpn: |
| 126 |
description: allow Global->VRF routes into EVPN |
| 127 |
type: bool |
| 128 |
inter_as_hybrid: &inter_as_hybrid |
| 129 |
description: Inter AS hybrid mode |
| 130 |
type: dict |
| 131 |
suboptions: |
| 132 |
csc: |
| 133 |
description: Carrier Supporting Carrier |
| 134 |
type: dict |
| 135 |
suboptions: |
| 136 |
next_hop: &next_hop |
| 137 |
description: Next-hop for the routes of a VRF in the backbone. |
| 138 |
type: str |
| 139 |
next_hop: *next_hop |
| 140 |
mdt: |
| 141 |
description: Backbone Multicast Distribution Tree |
| 142 |
type: dict |
| 143 |
suboptions: |
| 144 |
auto_discovery: |
| 145 |
description: BGP auto-discovery for MVPN |
| 146 |
type: dict |
| 147 |
suboptions: |
| 148 |
ingress_replication: |
| 149 |
description: BGP auto-discovery for Ingress-Replication |
| 150 |
type: dict |
| 151 |
suboptions: |
| 152 |
inter_as: |
| 153 |
description: Enable Inter-AS BGP auto-discovery |
| 154 |
type: dict |
| 155 |
suboptions: |
| 156 |
mdt_hello_enable: &mdt_hello_enable |
| 157 |
description: Enable PIM Hellos over MDT interface |
| 158 |
type: bool |
| 159 |
mdt_hello_enable: *mdt_hello_enable |
| 160 |
mldp: |
| 161 |
description: Use MLDP for MDT auto-discovery. |
| 162 |
type: bool |
| 163 |
pim: |
| 164 |
description: BGP auto-discovery for PIM |
| 165 |
type: dict |
| 166 |
suboptions: |
| 167 |
inter_as: |
| 168 |
description: Enable Inter-AS BGP auto-discovery |
| 169 |
type: dict |
| 170 |
suboptions: |
| 171 |
mdt_hello_enable: *mdt_hello_enable |
| 172 |
pim_tlv_announce: &pim_tlv_announce |
| 173 |
description: Announce PIM TLV for data MDT |
| 174 |
type: dict |
| 175 |
suboptions: |
| 176 |
mdt_hello_enable: *mdt_hello_enable |
| 177 |
mdt_hello_enable: *mdt_hello_enable |
| 178 |
pim_tlv_announce: *pim_tlv_announce |
| 179 |
receiver_site: |
| 180 |
description: BGP receiver only site for MVPN |
| 181 |
type: bool |
| 182 |
data: |
| 183 |
description: MDT data trees |
| 184 |
type: dict |
| 185 |
suboptions: |
| 186 |
ingress_replication: |
| 187 |
description: Use Ingress-Replication to create the data MDT |
| 188 |
type: dict |
| 189 |
suboptions: |
| 190 |
number: |
| 191 |
description: Number of data MDT |
| 192 |
type: int |
| 193 |
immediate_switch: |
| 194 |
description: Switch immediately to Data MDT tree |
| 195 |
type: bool |
| 196 |
list: &list |
| 197 |
description: Access-list |
| 198 |
type: dict |
| 199 |
suboptions: |
| 200 |
access_list_number: |
| 201 |
description: Access-list number |
| 202 |
type: int |
| 203 |
access_list_name: |
| 204 |
description: IP Named Extended Access list |
| 205 |
type: str |
| 206 |
list: *list |
| 207 |
mpls: |
| 208 |
description: Configure MPLS for data MDT |
| 209 |
type: dict |
| 210 |
suboptions: |
| 211 |
mldp: |
| 212 |
description: Use MLDP for MPLS data MDT |
| 213 |
type: int |
| 214 |
threshold: |
| 215 |
description: MDT switching threshold |
| 216 |
type: int |
| 217 |
default: |
| 218 |
description: Default MDT configuration |
| 219 |
type: dict |
| 220 |
suboptions: |
| 221 |
ingress_replication: |
| 222 |
description: Use Ingress-Replication for the default MDT |
| 223 |
type: bool |
| 224 |
direct: |
| 225 |
description: Direct MDT's |
| 226 |
type: bool |
| 227 |
log_reuse: |
| 228 |
description: Event logging for data MDT reuse |
| 229 |
type: bool |
| 230 |
mode: |
| 231 |
description: The type of encapsulation |
| 232 |
type: dict |
| 233 |
suboptions: |
| 234 |
gre: |
| 235 |
description: GRE encapsulation |
| 236 |
type: bool |
| 237 |
mtu: |
| 238 |
description: The MTU |
| 239 |
type: int |
| 240 |
overlay: |
| 241 |
description: MDT overlay Protocol |
| 242 |
type: dict |
| 243 |
suboptions: |
| 244 |
bgp: |
| 245 |
description: BGP Overlay signalling |
| 246 |
type: dict |
| 247 |
suboptions: |
| 248 |
shared_tree_prune_delay: |
| 249 |
description: Delay before shared tree is pruned at C-RP PE |
| 250 |
type: int |
| 251 |
source_tree_prune_delay: |
| 252 |
description: Delay before source tree is pruned at C-S PE |
| 253 |
type: int |
| 254 |
use_bgp: |
| 255 |
description: Use BGP for MDT overlay signaling |
| 256 |
type: dict |
| 257 |
suboptions: |
| 258 |
set: |
| 259 |
description: Enable the use of BGP for MDT overlay. |
| 260 |
type: bool |
| 261 |
spt_only: |
| 262 |
description: Enable SPT-only ASM mode |
| 263 |
type: bool |
| 264 |
partitioned: |
| 265 |
description: Partitioned Multicast Distribution Tree |
| 266 |
type: dict |
| 267 |
suboptions: |
| 268 |
ingress_replication: |
| 269 |
description: Use Ingress-Replication for the partitioned MDT |
| 270 |
type: bool |
| 271 |
mldp: |
| 272 |
description: Use MLDP for the partitioned MDT. |
| 273 |
type: dict |
| 274 |
suboptions: |
| 275 |
p2mp: |
| 276 |
description: Enable P2MP for partitioned MLDP MDT. |
| 277 |
type: bool |
| 278 |
strict_rpf: |
| 279 |
description: Enable strict RPF check |
| 280 |
type: dict |
| 281 |
suboptions: |
| 282 |
interface: |
| 283 |
description: Interface based strict RPF check |
| 284 |
type: bool |
| 285 |
protection: |
| 286 |
description: Configure local repair |
| 287 |
type: dict |
| 288 |
suboptions: |
| 289 |
local_prefixes: |
| 290 |
description: Enable protection for local prefixes |
| 291 |
type: bool |
| 292 |
route_replicate: &route_replicate |
| 293 |
description: Replicate (import) routes from another topology (and another VRF) |
| 294 |
type: dict |
| 295 |
suboptions: |
| 296 |
recursion_policy: |
| 297 |
description: Route replication recursion policy |
| 298 |
type: dict |
| 299 |
suboptions: |
| 300 |
destination: |
| 301 |
description: Recurse in destination topology |
| 302 |
type: bool |
| 303 |
from_config: |
| 304 |
description: Replicate routes from another VRF |
| 305 |
type: dict |
| 306 |
suboptions: |
| 307 |
multicast: |
| 308 |
description: Multicast SAFI |
| 309 |
type: dict |
| 310 |
suboptions: |
| 311 |
all: &all |
| 312 |
description: All routes |
| 313 |
type: dict |
| 314 |
suboptions: |
| 315 |
route_map: &route_map |
| 316 |
description: Route-map reference |
| 317 |
type: str |
| 318 |
bgp: &bgp |
| 319 |
description: Border Gateway Protocol (BGP) |
| 320 |
type: dict |
| 321 |
suboptions: |
| 322 |
as_number: |
| 323 |
description: Autonomous System Number |
| 324 |
type: int |
| 325 |
route_map: *route_map |
| 326 |
eigrp: &eigrp |
| 327 |
description: Enhanced Interior Gateway Routing Protocol (EIGRP) |
| 328 |
type: dict |
| 329 |
suboptions: |
| 330 |
as_number: |
| 331 |
description: Autonomous System Number |
| 332 |
type: int |
| 333 |
route_map: *route_map |
| 334 |
isis: &isis |
| 335 |
description: Intermediate System-to-Intermediate System (ISIS) |
| 336 |
type: dict |
| 337 |
suboptions: |
| 338 |
iso_tag: |
| 339 |
description: ISO routing area tag |
| 340 |
type: str |
| 341 |
route_map: *route_map |
| 342 |
mobile: &mobile |
| 343 |
description: Mobile routes |
| 344 |
type: dict |
| 345 |
suboptions: |
| 346 |
route_map: *route_map |
| 347 |
odr: &odr |
| 348 |
description: On-Demand Stub routes |
| 349 |
type: dict |
| 350 |
suboptions: |
| 351 |
route_map: *route_map |
| 352 |
ospf: &ospf |
| 353 |
description: Open Shortest Path First (OSPF) |
| 354 |
type: dict |
| 355 |
suboptions: |
| 356 |
process_id: |
| 357 |
description: OSPF process ID |
| 358 |
type: int |
| 359 |
route_map: *route_map |
| 360 |
rip: &rip |
| 361 |
description: Routing Information Protocol (RIP) |
| 362 |
type: dict |
| 363 |
suboptions: |
| 364 |
route_map: *route_map |
| 365 |
static: &static |
| 366 |
description: Static routes |
| 367 |
type: dict |
| 368 |
suboptions: |
| 369 |
route_map: *route_map |
| 370 |
topology: &topology |
| 371 |
description: Topology name |
| 372 |
type: dict |
| 373 |
suboptions: |
| 374 |
base: |
| 375 |
description: Base topology |
| 376 |
type: dict |
| 377 |
suboptions: |
| 378 |
all: *all |
| 379 |
bgp: *bgp |
| 380 |
eigrp: *eigrp |
| 381 |
isis: *isis |
| 382 |
mobile: *mobile |
| 383 |
odr: *odr |
| 384 |
ospf: *ospf |
| 385 |
rip: *rip |
| 386 |
static: *static |
| 387 |
unicast: |
| 388 |
description: Unicast SAFI |
| 389 |
type: dict |
| 390 |
suboptions: |
| 391 |
all: *all |
| 392 |
bgp: *bgp |
| 393 |
connected: |
| 394 |
description: Connected routes |
| 395 |
type: dict |
| 396 |
suboptions: |
| 397 |
route_map: *route_map |
| 398 |
eigrp: *eigrp |
| 399 |
isis: *isis |
| 400 |
mobile: *mobile |
| 401 |
odr: *odr |
| 402 |
ospf: *ospf |
| 403 |
rip: *rip |
| 404 |
static: *static |
| 405 |
vrf: |
| 406 |
description: Specify a source VRF |
| 407 |
type: dict |
| 408 |
suboptions: |
| 409 |
name: |
| 410 |
description: Source VRF name |
| 411 |
type: str |
| 412 |
multicast: |
| 413 |
description: Multicast SAFI |
| 414 |
type: dict |
| 415 |
suboptions: |
| 416 |
all: *all |
| 417 |
bgp: *bgp |
| 418 |
eigrp: *eigrp |
| 419 |
isis: *isis |
| 420 |
mobile: *mobile |
| 421 |
odr: *odr |
| 422 |
ospf: *ospf |
| 423 |
rip: *rip |
| 424 |
static: *static |
| 425 |
topology: *topology |
| 426 |
unicast: |
| 427 |
description: Unicast SAFI |
| 428 |
type: dict |
| 429 |
suboptions: |
| 430 |
all: *all |
| 431 |
bgp: *bgp |
| 432 |
connected: |
| 433 |
description: Connected routes |
| 434 |
type: dict |
| 435 |
suboptions: |
| 436 |
route_map: *route_map |
| 437 |
eigrp: *eigrp |
| 438 |
isis: *isis |
| 439 |
mobile: *mobile |
| 440 |
odr: *odr |
| 441 |
ospf: *ospf |
| 442 |
rip: *rip |
| 443 |
static: *static |
| 444 |
global: |
| 445 |
description: global VRF |
| 446 |
type: dict |
| 447 |
suboptions: |
| 448 |
multicast: |
| 449 |
description: Multicast SAFI |
| 450 |
type: dict |
| 451 |
suboptions: |
| 452 |
all: *all |
| 453 |
bgp: *bgp |
| 454 |
eigrp: *eigrp |
| 455 |
isis: *isis |
| 456 |
mobile: *mobile |
| 457 |
odr: *odr |
| 458 |
ospf: *ospf |
| 459 |
rip: *rip |
| 460 |
static: *static |
| 461 |
topology: *topology |
| 462 |
unicast: |
| 463 |
description: Unicast SAFI |
| 464 |
type: dict |
| 465 |
suboptions: |
| 466 |
all: *all |
| 467 |
bgp: *bgp |
| 468 |
connected: |
| 469 |
description: Connected routes |
| 470 |
type: dict |
| 471 |
suboptions: |
| 472 |
route_map: *route_map |
| 473 |
eigrp: *eigrp |
| 474 |
isis: *isis |
| 475 |
mobile: *mobile |
| 476 |
odr: *odr |
| 477 |
ospf: *ospf |
| 478 |
rip: *rip |
| 479 |
static: *static |
| 480 |
route_target: &route_target |
| 481 |
description: Specify Target VPN Extended Communities. |
| 482 |
type: dict |
| 483 |
suboptions: |
| 484 |
export: |
| 485 |
description: |
| 486 |
- This option is DEPRECATED and is replaced with exports which |
| 487 |
accepts list of dict input. |
| 488 |
type: str |
| 489 |
import_config: |
| 490 |
description: |
| 491 |
- This option is DEPRECATED and is replaced with imports which |
| 492 |
accepts list of dict input. |
| 493 |
type: str |
| 494 |
both: |
| 495 |
description: |
| 496 |
- This option is DEPRECATED and is replaced with both_options which |
| 497 |
accepts list of dict input. |
| 498 |
type: str |
| 499 |
exports: |
| 500 |
description: Export Target-VPN community. |
| 501 |
type: list |
| 502 |
elements: dict |
| 503 |
suboptions: |
| 504 |
rt_value: |
| 505 |
description: Export Target-VPN community. |
| 506 |
type: str |
| 507 |
stitching: |
| 508 |
description: Export Target-VPN community. |
| 509 |
type: bool |
| 510 |
|
| 511 |
imports: |
| 512 |
description: Export Target-VPN community. |
| 513 |
type: list |
| 514 |
elements: dict |
| 515 |
suboptions: |
| 516 |
rt_value: |
| 517 |
description: Export Target-VPN community. |
| 518 |
type: str |
| 519 |
stitching: |
| 520 |
description: Export Target-VPN community. |
| 521 |
type: bool |
| 522 |
|
| 523 |
both_options: |
| 524 |
description: Both export and import Target-VPN community |
| 525 |
type: list |
| 526 |
elements: dict |
| 527 |
suboptions: |
| 528 |
rt_value: |
| 529 |
description: Export Target-VPN community. |
| 530 |
type: str |
| 531 |
stitching: |
| 532 |
description: Export Target-VPN community. |
| 533 |
type: bool |
| 534 |
|
| 535 |
running_config: |
| 536 |
description: |
| 537 |
- This option is used only with state I(parsed). |
| 538 |
- The value of this option should be the output received from the IOS device by |
| 539 |
executing the command B(show running-config vrf). |
| 540 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 541 |
transforms it into Ansible structured data as per the resource module's argspec |
| 542 |
and the value is then returned in the I(parsed) key within the result. |
| 543 |
type: str |
| 544 |
state: |
| 545 |
choices: [parsed, gathered, deleted, merged, replaced, rendered, overridden] |
| 546 |
default: merged |
| 547 |
description: |
| 548 |
- The state the configuration should be left in |
| 549 |
- The states I(rendered), I(gathered) and I(parsed) does not perform any change |
| 550 |
on the device. |
| 551 |
- The state I(rendered) will transform the configuration in C(config) option to |
| 552 |
platform specific CLI commands which will be returned in the I(rendered) key |
| 553 |
within the result. For state I(rendered) active connection to remote host is |
| 554 |
not required. |
| 555 |
- The state I(gathered) will fetch the running configuration from device and transform |
| 556 |
it into structured data in the format as per the resource module argspec and |
| 557 |
the value is returned in the I(gathered) key within the result. |
| 558 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 559 |
transforms it into JSON format as per the resource module parameters and the |
| 560 |
value is returned in the I(parsed) key within the result. The value of C(running_config) |
| 561 |
option should be the same format as the output of command I(show running-config vrf). |
| 562 |
connection to remote host is not required. |
| 563 |
type: str |
| 564 |
""" |
| 565 |
|
| 566 |
EXAMPLES = """ |
| 567 |
# Using merged |
| 568 |
# |
| 569 |
# Before state: |
| 570 |
# ------------- |
| 571 |
# |
| 572 |
# RP/0/0/CPU0:ios#show running-config | section ^vrf |
| 573 |
# vrf defnition test |
| 574 |
# |
| 575 |
|
| 576 |
- name: Merge provided configuration with device configuration |
| 577 |
cisco.ios.ios_vrf_address_family: |
| 578 |
config: |
| 579 |
- name: test1 |
| 580 |
address_families: |
| 581 |
- afi: "ipv4" |
| 582 |
safi: "unicast" |
| 583 |
bgp: |
| 584 |
next_hop: |
| 585 |
loopback: 40 |
| 586 |
export: |
| 587 |
ipv4: |
| 588 |
multicast: |
| 589 |
map: "single" |
| 590 |
prefix: 345 |
| 591 |
unicast: |
| 592 |
allow_evpn: true |
| 593 |
map: "test-map" |
| 594 |
prefix: 67 |
| 595 |
map: "testing-map" |
| 596 |
import_config: |
| 597 |
ipv4: |
| 598 |
multicast: |
| 599 |
map: "import-map" |
| 600 |
prefix: 89 |
| 601 |
unicast: |
| 602 |
allow_evpn: true |
| 603 |
limit: 12 |
| 604 |
map: "ran-map" |
| 605 |
map: "import-map" |
| 606 |
state: merged |
| 607 |
|
| 608 |
# Task Output: |
| 609 |
# ------------ |
| 610 |
# |
| 611 |
# before: [] |
| 612 |
# |
| 613 |
# commands: |
| 614 |
# - vrf definition test1 |
| 615 |
# - address-family ipv4 unicast |
| 616 |
# - bgp next-hop loopback 40 |
| 617 |
# - export map "testing-map" |
| 618 |
# - export ipv4 multicast 345 map "single" |
| 619 |
# - export ipv4 unicast 67 map "test-map" allow-evpn |
| 620 |
# - import map "import-map" |
| 621 |
# - import ipv4 multicast 89 map "import-map" |
| 622 |
# - import ipv4 unicast 12 map "ran-map" allow-evpn |
| 623 |
# |
| 624 |
# after: |
| 625 |
# - name: test1 |
| 626 |
# address_families: |
| 627 |
# - afi: "ipv4" |
| 628 |
# safi: "unicast" |
| 629 |
# bgp: |
| 630 |
# next_hop: |
| 631 |
# loopback: 40 |
| 632 |
# export: |
| 633 |
# ipv4: |
| 634 |
# multicast: |
| 635 |
# map: "single" |
| 636 |
# prefix: 345 |
| 637 |
# unicast: |
| 638 |
# allow_evpn: true |
| 639 |
# map: "test-map" |
| 640 |
# prefix: 67 |
| 641 |
# map: "testing-map" |
| 642 |
# import_config: |
| 643 |
# ipv4: |
| 644 |
# multicast: |
| 645 |
# map: "import-map" |
| 646 |
# prefix: 89 |
| 647 |
# unicast: |
| 648 |
# allow_evpn: true |
| 649 |
# limit: 12 |
| 650 |
# map: "ran-map" |
| 651 |
# map: "import-map" |
| 652 |
# |
| 653 |
# After state: |
| 654 |
# ------------ |
| 655 |
# |
| 656 |
# RP/0/0/CPU0:ios#show running-config | section ^vrf |
| 657 |
# vrf definition test1 |
| 658 |
# address-family ipv4 unicast |
| 659 |
# bgp next-hop loopback 40 |
| 660 |
# export map "testing-map" |
| 661 |
# export ipv4 multicast 345 map "single" |
| 662 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 663 |
# import map "import-map" |
| 664 |
# import ipv4 multicast 89 map "import-map" |
| 665 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 666 |
|
| 667 |
# Using replaced |
| 668 |
# |
| 669 |
# Before state: |
| 670 |
# ------------- |
| 671 |
# |
| 672 |
# RP/0/0/CPU0:ios#show running-config | section ^vrf |
| 673 |
# vrf definition test1 |
| 674 |
# address-family ipv4 unicast |
| 675 |
# bgp next-hop loopback 40 |
| 676 |
# export map "testing-map" |
| 677 |
# export ipv4 multicast 345 map "single" |
| 678 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 679 |
# import map "import-map" |
| 680 |
# import ipv4 multicast 89 map "import-map" |
| 681 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 682 |
|
| 683 |
- name: Replace the provided configuration with the existing running configuration |
| 684 |
cisco.ios.ios_vrf_address_family: |
| 685 |
config: |
| 686 |
- name: test1 |
| 687 |
address_families: |
| 688 |
- afi: "ipv4" |
| 689 |
safi: "unicast" |
| 690 |
bgp: |
| 691 |
next_hop: |
| 692 |
loopback: 40 |
| 693 |
export: |
| 694 |
ipv4: |
| 695 |
multicast: |
| 696 |
map: "single" |
| 697 |
prefix: 345 |
| 698 |
unicast: |
| 699 |
allow_evpn: true |
| 700 |
map: "test-map" |
| 701 |
prefix: 67 |
| 702 |
map: "testing-map" |
| 703 |
import_config: |
| 704 |
ipv4: |
| 705 |
multicast: |
| 706 |
map: "import-map" |
| 707 |
prefix: 89 |
| 708 |
unicast: |
| 709 |
allow_evpn: true |
| 710 |
limit: 12 |
| 711 |
map: "ran-map" |
| 712 |
map: "import-map" |
| 713 |
state: replaced |
| 714 |
|
| 715 |
# Task Output: |
| 716 |
# ------------ |
| 717 |
# |
| 718 |
# before: |
| 719 |
# - name: test1 |
| 720 |
# address_families: |
| 721 |
# - afi: "ipv4" |
| 722 |
# safi: "unicast" |
| 723 |
# bgp: |
| 724 |
# next_hop: |
| 725 |
# loopback: 40 |
| 726 |
# export: |
| 727 |
# ipv4: |
| 728 |
# multicast: |
| 729 |
# map: "single" |
| 730 |
# prefix: 345 |
| 731 |
# unicast: |
| 732 |
# allow_evpn: true |
| 733 |
# map: "test-map" |
| 734 |
# prefix: 67 |
| 735 |
# map: "testing-map" |
| 736 |
# import_config: |
| 737 |
# ipv4: |
| 738 |
# multicast: |
| 739 |
# map: "import-map" |
| 740 |
# prefix: 89 |
| 741 |
# unicast: |
| 742 |
# allow_evpn: true |
| 743 |
# limit: 12 |
| 744 |
# map: "ran-map" |
| 745 |
# map: "import-map" |
| 746 |
# |
| 747 |
# commands: |
| 748 |
# - vrf definition test1 |
| 749 |
# - address-family ipv4 unicast |
| 750 |
# - bgp next-hop loopback 40 |
| 751 |
# - export map "testing-map" |
| 752 |
# - export ipv4 multicast 345 map "single" |
| 753 |
# - export ipv4 unicast 67 map "test-map" allow-evpn |
| 754 |
# - import map "import-map" |
| 755 |
# - import ipv4 multicast 89 map "import-map" |
| 756 |
# - import ipv4 unicast 12 map "ran-map" allow-evpn |
| 757 |
# |
| 758 |
# after: |
| 759 |
# - name: VRF1 |
| 760 |
# address_families: |
| 761 |
# - afi: "ipv4" |
| 762 |
# safi: "unicast" |
| 763 |
# bgp: |
| 764 |
# next_hop: |
| 765 |
# loopback: 23 |
| 766 |
# export: |
| 767 |
# ipv4: |
| 768 |
# multicast: |
| 769 |
# map: "single" |
| 770 |
# prefix: 33 |
| 771 |
# unicast: |
| 772 |
# allow_evpn: true |
| 773 |
# map: "test-map1" |
| 774 |
# prefix: 7 |
| 775 |
# map: "testing-map" |
| 776 |
# import_config: |
| 777 |
# ipv4: |
| 778 |
# multicast: |
| 779 |
# map: "import-map1" |
| 780 |
# prefix: 89 |
| 781 |
# unicast: |
| 782 |
# allow_evpn: true |
| 783 |
# limit: 12 |
| 784 |
# map: "ran-map" |
| 785 |
# map: "import-map" |
| 786 |
# |
| 787 |
# After state: |
| 788 |
# ------------ |
| 789 |
# |
| 790 |
# RP/0/RP0/CPU0:ios(config)#show running-config vrf |
| 791 |
# vrf definition VRF1 |
| 792 |
# address-family ipv4 unicast |
| 793 |
# bgp next-hop loopback 23 |
| 794 |
# export map "testing-map" |
| 795 |
# export ipv4 multicast 345 map "single" |
| 796 |
# export ipv4 unicast 67 map "test-map1" allow-evpn |
| 797 |
# import map "import-map" |
| 798 |
# import ipv4 multicast 89 map "import-map1" |
| 799 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 800 |
|
| 801 |
# Using overridden |
| 802 |
# |
| 803 |
# Before state: |
| 804 |
# ------------- |
| 805 |
# |
| 806 |
# RP/0/RP0/CPU0:ios(config)#show running-config | section ^vrf |
| 807 |
# vrf definition test1 |
| 808 |
# address-family ipv4 unicast |
| 809 |
# bgp next-hop loopback 40 |
| 810 |
# export map "testing-map" |
| 811 |
# export ipv4 multicast 345 map "single" |
| 812 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 813 |
# import map "import-map" |
| 814 |
# import ipv4 multicast 89 map "import-map" |
| 815 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 816 |
|
| 817 |
- name: Override the provided configuration with the existing running configuration |
| 818 |
cisco.ios.ios_vrf_address_family: |
| 819 |
state: overridden |
| 820 |
config: |
| 821 |
- name: VRF7 |
| 822 |
address_families: |
| 823 |
- afi: "ipv4" |
| 824 |
safi: "unicast" |
| 825 |
bgp: |
| 826 |
next_hop: |
| 827 |
loopback: 89 |
| 828 |
export: |
| 829 |
ipv4: |
| 830 |
multicast: |
| 831 |
map: "single" |
| 832 |
prefix: 345 |
| 833 |
unicast: |
| 834 |
allow_evpn: true |
| 835 |
map: "test-map" |
| 836 |
prefix: 67 |
| 837 |
map: "testing-map" |
| 838 |
import_config: |
| 839 |
ipv4: |
| 840 |
multicast: |
| 841 |
map: "import-map" |
| 842 |
prefix: 89 |
| 843 |
unicast: |
| 844 |
allow_evpn: true |
| 845 |
limit: 12 |
| 846 |
map: "ran-map" |
| 847 |
map: "import-map" |
| 848 |
# Task Output: |
| 849 |
# ------------ |
| 850 |
# |
| 851 |
# before: |
| 852 |
# - name: test1 |
| 853 |
# address_families: |
| 854 |
# - afi: "ipv4" |
| 855 |
# safi: "unicast" |
| 856 |
# bgp: |
| 857 |
# next_hop: |
| 858 |
# loopback: 40 |
| 859 |
# export: |
| 860 |
# ipv4: |
| 861 |
# multicast: |
| 862 |
# map: "single" |
| 863 |
# prefix: 345 |
| 864 |
# unicast: |
| 865 |
# allow_evpn: true |
| 866 |
# map: "test-map" |
| 867 |
# prefix: 67 |
| 868 |
# map: "testing-map" |
| 869 |
# import_config: |
| 870 |
# ipv4: |
| 871 |
# multicast: |
| 872 |
# map: "import-map" |
| 873 |
# prefix: 89 |
| 874 |
# unicast: |
| 875 |
# allow_evpn: true |
| 876 |
# limit: 12 |
| 877 |
# map: "ran-map" |
| 878 |
# map: "import-map" |
| 879 |
# |
| 880 |
# commands: |
| 881 |
# - vrf definition VRF7 |
| 882 |
# - address-family ipv4 unicast |
| 883 |
# - bgp next-hop loopback 89 |
| 884 |
# - export map "testing-map" |
| 885 |
# - export ipv4 multicast 345 map "single" |
| 886 |
# - export ipv4 unicast 67 map "test-map" allow-evpn |
| 887 |
# - import map "import-map" |
| 888 |
# - import ipv4 multicast 89 map "import-map" |
| 889 |
# - import ipv4 unicast 12 map "ran-map" allow-evpn |
| 890 |
|
| 891 |
# |
| 892 |
# After state: |
| 893 |
# ------------- |
| 894 |
# RP/0/RP0/CPU0:ios(config)#show running-config vrf |
| 895 |
# vrf definition VRF4 |
| 896 |
# vrf definition VRF7 |
| 897 |
# address-family ipv4 unicast |
| 898 |
# bgp next-hop loopback 89 |
| 899 |
# export map "testing-map" |
| 900 |
# export ipv4 multicast 345 map "single" |
| 901 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 902 |
# import map "import-map" |
| 903 |
# import ipv4 multicast 89 map "import-map1" |
| 904 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 905 |
|
| 906 |
# Using deleted |
| 907 |
# |
| 908 |
# Before state: |
| 909 |
# ------------- |
| 910 |
# |
| 911 |
# RP/0/RP0/CPU0:ios(config)#show running-config | section ^vrf |
| 912 |
# vrf definition VRF4 |
| 913 |
# vrf definition VRF6 |
| 914 |
# address-family ipv4 unicast |
| 915 |
# bgp next-hop loopback 40 |
| 916 |
# import map "import-map" |
| 917 |
# import ipv4 multicast 89 map "import-map" |
| 918 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 919 |
# export map "testing-map" |
| 920 |
# export ipv4 multicast 345 map "single" |
| 921 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 922 |
# vrf definition VRF7 |
| 923 |
|
| 924 |
- name: Delete the provided configuration |
| 925 |
cisco.ios.ios_vrf_address_family: |
| 926 |
config: |
| 927 |
state: deleted |
| 928 |
|
| 929 |
# Task Output: |
| 930 |
# ------------ |
| 931 |
# |
| 932 |
# before: |
| 933 |
# - name: VRF4 |
| 934 |
# - name: VRF6 |
| 935 |
# address_families: |
| 936 |
# - afi: "ipv4" |
| 937 |
# safi: "unicast" |
| 938 |
# bgp: |
| 939 |
# next_hop: |
| 940 |
# loopback: 23 |
| 941 |
# import_config: |
| 942 |
# ipv4: |
| 943 |
# multicast: |
| 944 |
# map: "import-map" |
| 945 |
# prefix: 89 |
| 946 |
# unicast: |
| 947 |
# map: "ran-map" |
| 948 |
# limit: 12 |
| 949 |
# allow_evpn: true |
| 950 |
# map: "import-map" |
| 951 |
# export: |
| 952 |
# ipv4: |
| 953 |
# multicast: |
| 954 |
# map: "single" |
| 955 |
# prefix: 345 |
| 956 |
# unicast: |
| 957 |
# map: "test-map" |
| 958 |
# prefix: 67 |
| 959 |
# allow_evpn: true |
| 960 |
# map: "testing-map" |
| 961 |
# - name: VRF7 |
| 962 |
|
| 963 |
# commands: |
| 964 |
# - vrf definition VRF4 |
| 965 |
# - vrf definition VRF6 |
| 966 |
# - no address-family ipv4 unicast |
| 967 |
# - vrf definition VRF7 |
| 968 |
# |
| 969 |
# after: |
| 970 |
# - name: VRF4 |
| 971 |
# - name: VRF6 |
| 972 |
# - name: VRF7 |
| 973 |
# |
| 974 |
# After state: |
| 975 |
# ------------ |
| 976 |
# |
| 977 |
# RP/0/RP0/CPU0:ios(config)#show running-config | section ^vrf |
| 978 |
# vrf definition VRF4 |
| 979 |
# vrf definition VRF6 |
| 980 |
# vrf definition VRF7 |
| 981 |
|
| 982 |
# Using rendered |
| 983 |
# |
| 984 |
- name: Render provided configuration with device configuration |
| 985 |
cisco.ios.ios_vrf_address_family: |
| 986 |
config: |
| 987 |
- name: test |
| 988 |
address_families: |
| 989 |
- afi: "ipv4" |
| 990 |
safi: "unicast" |
| 991 |
bgp: |
| 992 |
next_hop: |
| 993 |
loopback: 23 |
| 994 |
import_config: |
| 995 |
ipv4: |
| 996 |
multicast: |
| 997 |
map: "import-map" |
| 998 |
prefix: 89 |
| 999 |
unicast: |
| 1000 |
map: "ran-map" |
| 1001 |
limit: 12 |
| 1002 |
allow_evpn: true |
| 1003 |
map: "import-map" |
| 1004 |
export: |
| 1005 |
ipv4: |
| 1006 |
multicast: |
| 1007 |
map: "single" |
| 1008 |
prefix: 345 |
| 1009 |
unicast: |
| 1010 |
map: "test-map" |
| 1011 |
prefix: 67 |
| 1012 |
allow_evpn: true |
| 1013 |
map: "testing-map" |
| 1014 |
state: rendered |
| 1015 |
|
| 1016 |
# Task Output: |
| 1017 |
# ------------ |
| 1018 |
# |
| 1019 |
# rendered: |
| 1020 |
# - vrf definition test |
| 1021 |
# - address-family ipv4 unicast |
| 1022 |
# - bgp next-hop loopback 23 |
| 1023 |
# - import map "import-map" |
| 1024 |
# - import ipv4 multicast 89 map "import-map" |
| 1025 |
# - import ipv4 unicast 12 map "ran-map" allow-evpn |
| 1026 |
# - export map "testing-map" |
| 1027 |
# - export ipv4 multicast 345 map "single" |
| 1028 |
# - export ipv4 unicast 67 map "test-map" allow-evpn |
| 1029 |
|
| 1030 |
# Using gathered |
| 1031 |
# |
| 1032 |
# Before state: |
| 1033 |
# ------------- |
| 1034 |
# |
| 1035 |
# RP/0/RP0/CPU0:ios(config)#show running-config | section ^vrf |
| 1036 |
# vrf definition test1 |
| 1037 |
# address-family ipv4 unicast |
| 1038 |
# bgp next-hop loopback 40 |
| 1039 |
# import map "import-map" |
| 1040 |
# import ipv4 multicast 89 map "import-map" |
| 1041 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 1042 |
# export map "testing-map" |
| 1043 |
# export ipv4 multicast 345 map "single" |
| 1044 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 1045 |
|
| 1046 |
- name: Gather existing running configuration |
| 1047 |
cisco.ios.ios_vrf_address_family: |
| 1048 |
state: gathered |
| 1049 |
|
| 1050 |
# Task Output: |
| 1051 |
# ------------ |
| 1052 |
# |
| 1053 |
# gathered: |
| 1054 |
# - name: test1 |
| 1055 |
# address_families: |
| 1056 |
# - afi: "ipv4" |
| 1057 |
# safi: "unicast" |
| 1058 |
# bgp: |
| 1059 |
# next_hop: |
| 1060 |
# loopback: 40 |
| 1061 |
# export: |
| 1062 |
# ipv4: |
| 1063 |
# multicast: |
| 1064 |
# map: "single" |
| 1065 |
# prefix: 345 |
| 1066 |
# unicast: |
| 1067 |
# allow_evpn: true |
| 1068 |
# map: "test-map" |
| 1069 |
# prefix: 67 |
| 1070 |
# map: "testing-map" |
| 1071 |
# import_config: |
| 1072 |
# ipv4: |
| 1073 |
# multicast: |
| 1074 |
# map: "import-map" |
| 1075 |
# prefix: 89 |
| 1076 |
# unicast: |
| 1077 |
# allow_evpn: true |
| 1078 |
# limit: 12 |
| 1079 |
# map: "ran-map" |
| 1080 |
# map: "import-map" |
| 1081 |
|
| 1082 |
# Using parsed |
| 1083 |
# |
| 1084 |
# File: parsed.cfg |
| 1085 |
# ---------------- |
| 1086 |
# |
| 1087 |
# vrf definition test |
| 1088 |
# address-family ipv4 unicast |
| 1089 |
# bgp next-hop loopback 23 |
| 1090 |
# import map "import-map" |
| 1091 |
# import ipv4 multicast 89 map "import-map" |
| 1092 |
# import ipv4 unicast 12 map "ran-map" allow-evpn |
| 1093 |
# export map "testing-map" |
| 1094 |
# export ipv4 multicast 345 map "single" |
| 1095 |
# export ipv4 unicast 67 map "test-map" allow-evpn |
| 1096 |
|
| 1097 |
- name: Parse the provided configuration |
| 1098 |
cisco.ios.ios_vrf_address_family: |
| 1099 |
running_config: "{{ lookup('file', 'parsed.cfg') }}" |
| 1100 |
state: parsed |
| 1101 |
|
| 1102 |
# Task Output: |
| 1103 |
# ------------ |
| 1104 |
# |
| 1105 |
# parsed: |
| 1106 |
# - address_families: |
| 1107 |
# - afi: ipv4 |
| 1108 |
# bgp: |
| 1109 |
# next_hop: |
| 1110 |
# loopback: 40 |
| 1111 |
# export: |
| 1112 |
# ipv4: |
| 1113 |
# multicast: |
| 1114 |
# map: "single" |
| 1115 |
# prefix: 345 |
| 1116 |
# unicast: |
| 1117 |
# allow_evpn: true |
| 1118 |
# map: "test-map" |
| 1119 |
# prefix: 67 |
| 1120 |
# map: "testing-map" |
| 1121 |
# import_config: |
| 1122 |
# ipv4: |
| 1123 |
# multicast: |
| 1124 |
# map: "import-map" |
| 1125 |
# prefix: 89 |
| 1126 |
# unicast: |
| 1127 |
# allow_evpn: true |
| 1128 |
# limit: 12 |
| 1129 |
# map: "ran-map" |
| 1130 |
# safi: unicast |
| 1131 |
# name: test |
| 1132 |
""" |
| 1133 |
|
| 1134 |
RETURN = """ |
| 1135 |
before: |
| 1136 |
description: The configuration prior to the module execution. |
| 1137 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 1138 |
type: list |
| 1139 |
sample: > |
| 1140 |
This output will always be in the same format as the |
| 1141 |
module argspec. |
| 1142 |
after: |
| 1143 |
description: The resulting configuration after module execution. |
| 1144 |
returned: when changed |
| 1145 |
type: list |
| 1146 |
sample: > |
| 1147 |
This output will always be in the same format as the |
| 1148 |
module argspec. |
| 1149 |
commands: |
| 1150 |
description: The set of commands pushed to the remote device. |
| 1151 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) |
| 1152 |
type: list |
| 1153 |
sample: |
| 1154 |
- vrf definition test1 |
| 1155 |
- address-family ipv4 unicast |
| 1156 |
- bgp next-hop loopback 40 |
| 1157 |
- export map "testing-map" |
| 1158 |
- export ipv4 multicast 345 map "testmap" |
| 1159 |
rendered: |
| 1160 |
description: The provided configuration in the task rendered in device-native format (offline). |
| 1161 |
returned: when I(state) is C(rendered) |
| 1162 |
type: list |
| 1163 |
sample: |
| 1164 |
- vrf definition test1 |
| 1165 |
- address-family ipv4 unicast |
| 1166 |
- bgp next-hop loopback 40 |
| 1167 |
- import map "testing-map" |
| 1168 |
- export ipv4 multicast 345 map "testmap" |
| 1169 |
gathered: |
| 1170 |
description: Facts about the network resource gathered from the remote device as structured data. |
| 1171 |
returned: when I(state) is C(gathered) |
| 1172 |
type: list |
| 1173 |
sample: > |
| 1174 |
This output will always be in the same format as the |
| 1175 |
module argspec. |
| 1176 |
parsed: |
| 1177 |
description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. |
| 1178 |
returned: when I(state) is C(parsed) |
| 1179 |
type: list |
| 1180 |
sample: > |
| 1181 |
This output will always be in the same format as the |
| 1182 |
module argspec. |
| 1183 |
""" |
| 1184 |
|
| 1185 |
from ansible.module_utils.basic import AnsibleModule |
| 1186 |
|
| 1187 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vrf_address_family.vrf_address_family import ( |
| 1188 |
Vrf_address_familyArgs, |
| 1189 |
) |
| 1190 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vrf_address_family.vrf_address_family import ( |
| 1191 |
Vrf_address_family, |
| 1192 |
) |
| 1193 |
|
| 1194 |
|
| 1195 |
def main(): |
| 1196 |
""" |
| 1197 |
Main entry point for module execution |
| 1198 |
|
| 1199 |
:returns: the result form module invocation |
| 1200 |
""" |
| 1201 |
module = AnsibleModule( |
| 1202 |
argument_spec=Vrf_address_familyArgs.argument_spec, |
| 1203 |
mutually_exclusive=[["config", "running_config"]], |
| 1204 |
required_if=[ |
| 1205 |
["state", "merged", ["config"]], |
| 1206 |
["state", "replaced", ["config"]], |
| 1207 |
["state", "overridden", ["config"]], |
| 1208 |
["state", "rendered", ["config"]], |
| 1209 |
["state", "parsed", ["running_config"]], |
| 1210 |
], |
| 1211 |
supports_check_mode=True, |
| 1212 |
) |
| 1213 |
|
| 1214 |
result = Vrf_address_family(module).execute_module() |
| 1215 |
module.exit_json(**result) |
| 1216 |
|
| 1217 |
|
| 1218 |
if __name__ == "__main__": |
| 1219 |
main() |