| 1 |
#!/usr/bin/python |
| 2 |
# |
| 3 |
# This file is part of Ansible |
| 4 |
# |
| 5 |
# Ansible is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Ansible is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
""" |
| 19 |
The module file for ios_vlans |
| 20 |
""" |
| 21 |
from __future__ import absolute_import, division, print_function |
| 22 |
|
| 23 |
|
| 24 |
__metaclass__ = type |
| 25 |
|
| 26 |
DOCUMENTATION = """ |
| 27 |
module: ios_vlans |
| 28 |
short_description: Resource module to configure VLANs. |
| 29 |
description: |
| 30 |
This module provides declarative management of VLANs on Cisco IOS network |
| 31 |
devices. |
| 32 |
version_added: 1.0.0 |
| 33 |
author: |
| 34 |
- Sumit Jaiswal (@justjais) |
| 35 |
- Sagar Paul (@KB-perByte) |
| 36 |
- Padmini Priyadarshini Sivaraj (@PadminiSivaraj) |
| 37 |
notes: |
| 38 |
- Tested against Cisco IOS-XE device with Version 17.13.01 on Cat9k on CML. |
| 39 |
- Starting from v2.5.0, this module will fail when run against Cisco IOS devices that do |
| 40 |
not support VLANs. The offline states (C(rendered) and C(parsed)) will work as expected. |
| 41 |
- This module works with connection C(network_cli). |
| 42 |
See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html) |
| 43 |
options: |
| 44 |
config: |
| 45 |
description: A dictionary of VLANs options |
| 46 |
type: list |
| 47 |
elements: dict |
| 48 |
suboptions: |
| 49 |
name: |
| 50 |
description: |
| 51 |
- Ascii name of the VLAN. |
| 52 |
- NOTE, I(name) should not be named/appended with I(default) as it is reserved |
| 53 |
for device default vlans. |
| 54 |
type: str |
| 55 |
vlan_id: |
| 56 |
description: |
| 57 |
- ID of the VLAN. Range 1-4094 |
| 58 |
type: int |
| 59 |
required: true |
| 60 |
mtu: |
| 61 |
description: |
| 62 |
- VLAN Maximum Transmission Unit. |
| 63 |
- Refer to vendor documentation for valid values. |
| 64 |
- This option is DEPRECATED use ios_interfaces to configure mtu, |
| 65 |
this attribute will be removed after 2027-01-01. |
| 66 |
- mtu is collected as part of facts, |
| 67 |
but a mtu command wont be fired if the configuration |
| 68 |
is present in the playbook. |
| 69 |
type: int |
| 70 |
state: |
| 71 |
description: |
| 72 |
- Operational state of the VLAN |
| 73 |
type: str |
| 74 |
choices: |
| 75 |
- active |
| 76 |
- suspend |
| 77 |
remote_span: |
| 78 |
description: |
| 79 |
- Configure as Remote SPAN VLAN |
| 80 |
type: bool |
| 81 |
shutdown: |
| 82 |
description: |
| 83 |
- Specifies whether VLAN switching should be administratively enabled or disabled. |
| 84 |
- When set to C(enabled), the VLAN interface is administratively shut down, which prevents it from forwarding traffic. |
| 85 |
- When set to C(disabled), the VLAN interface is administratively enabled by issuing the internal C(no shutdown) command, |
| 86 |
allowing it to forward traffic. |
| 87 |
- The operational state of the VLAN depends on both the administrative state (C(shutdown) or C(no shutdown)) and the physical link status. |
| 88 |
type: str |
| 89 |
choices: |
| 90 |
- enabled |
| 91 |
- disabled |
| 92 |
private_vlan: |
| 93 |
description: |
| 94 |
- Options for private vlan configuration. |
| 95 |
type: dict |
| 96 |
suboptions: |
| 97 |
type: |
| 98 |
description: |
| 99 |
- Private VLAN type |
| 100 |
type: str |
| 101 |
choices: |
| 102 |
- primary |
| 103 |
- isolated |
| 104 |
- community |
| 105 |
associated: |
| 106 |
description: |
| 107 |
- "List of private VLANs associated with the primary . Only works with `type: primary`." |
| 108 |
type: list |
| 109 |
elements: int |
| 110 |
member: |
| 111 |
description: |
| 112 |
- Members of VLAN |
| 113 |
type: dict |
| 114 |
suboptions: |
| 115 |
vni: |
| 116 |
description: |
| 117 |
- VXLAN vni |
| 118 |
type: int |
| 119 |
required: true |
| 120 |
evi: |
| 121 |
description: |
| 122 |
- Ethernet Virtual Private Network (EVPN) |
| 123 |
type: int |
| 124 |
running_config: |
| 125 |
description: |
| 126 |
- This option is used only with state I(parsed). |
| 127 |
- The value of this option should be the output received from the IOS device |
| 128 |
by executing the command B(show vlan). |
| 129 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 130 |
transforms it into Ansible structured data as per the resource module's argspec |
| 131 |
and the value is then returned in the I(parsed) key within the result. |
| 132 |
type: str |
| 133 |
state: |
| 134 |
description: |
| 135 |
- The state the configuration should be left in |
| 136 |
- The states I(rendered), I(gathered) and I(parsed) does not perform any change |
| 137 |
on the device. |
| 138 |
- The state I(rendered) will transform the configuration in C(config) option to |
| 139 |
platform specific CLI commands which will be returned in the I(rendered) key |
| 140 |
within the result. For state I(rendered) active connection to remote host is |
| 141 |
not required. |
| 142 |
- The state I(gathered) will fetch the running configuration from device and transform |
| 143 |
it into structured data in the format as per the resource module argspec and |
| 144 |
the value is returned in the I(gathered) key within the result. |
| 145 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 146 |
transforms it into JSON format as per the resource module parameters and the |
| 147 |
value is returned in the I(parsed) key within the result. The value of C(running_config) |
| 148 |
option should be the same format as the output of commands I(show vlan) and I(show |
| 149 |
running-config | sec ^vlan configuration .+) executed on device. For state I(parsed) active |
| 150 |
connection to remote host is not required. |
| 151 |
type: str |
| 152 |
choices: |
| 153 |
- merged |
| 154 |
- replaced |
| 155 |
- overridden |
| 156 |
- deleted |
| 157 |
- rendered |
| 158 |
- gathered |
| 159 |
- purged |
| 160 |
- parsed |
| 161 |
default: merged |
| 162 |
""" |
| 163 |
|
| 164 |
EXAMPLES = """ |
| 165 |
# Using merged |
| 166 |
|
| 167 |
# Before state: |
| 168 |
# ------------- |
| 169 |
# |
| 170 |
# vios_l2#show vlan |
| 171 |
# VLAN Name Status Ports |
| 172 |
# ---- -------------------------------- --------- ------------------------------- |
| 173 |
# 1 default active Gi0/1, Gi0/2 |
| 174 |
# 1002 fddi-default act/unsup |
| 175 |
# 1003 token-ring-default act/unsup |
| 176 |
# 1004 fddinet-default act/unsup |
| 177 |
# 1005 trnet-default act/unsup |
| 178 |
# |
| 179 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 180 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 181 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 182 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 183 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 184 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 185 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 186 |
|
| 187 |
- name: Merge provided configuration with device configuration |
| 188 |
cisco.ios.ios_vlans: |
| 189 |
config: |
| 190 |
- name: Vlan_10 |
| 191 |
vlan_id: 10 |
| 192 |
state: active |
| 193 |
shutdown: disabled |
| 194 |
remote_span: true |
| 195 |
- name: Vlan_20 |
| 196 |
vlan_id: 20 |
| 197 |
mtu: 610 |
| 198 |
state: active |
| 199 |
shutdown: enabled |
| 200 |
- name: Vlan_30 |
| 201 |
vlan_id: 30 |
| 202 |
state: suspend |
| 203 |
shutdown: enabled |
| 204 |
state: merged |
| 205 |
|
| 206 |
# After state: |
| 207 |
# ------------ |
| 208 |
# |
| 209 |
# vios_l2#show vlan |
| 210 |
# VLAN Name Status Ports |
| 211 |
# ---- -------------------------------- --------- ------------------------------- |
| 212 |
# 1 default active Gi0/1, Gi0/2 |
| 213 |
# 10 vlan_10 active |
| 214 |
# 20 vlan_20 act/lshut |
| 215 |
# 30 vlan_30 sus/lshut |
| 216 |
# 1002 fddi-default act/unsup |
| 217 |
# 1003 token-ring-default act/unsup |
| 218 |
# 1004 fddinet-default act/unsup |
| 219 |
# 1005 trnet-default act/unsup |
| 220 |
# |
| 221 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 222 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 223 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 224 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 225 |
# 20 enet 100020 610 - - - - - 0 0 |
| 226 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 227 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 228 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 229 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 230 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 231 |
# |
| 232 |
# Remote SPAN VLANs |
| 233 |
# ------------------------------------------------------------------------------ |
| 234 |
# 10 |
| 235 |
|
| 236 |
# Using merged |
| 237 |
|
| 238 |
# Before state: |
| 239 |
# ------------- |
| 240 |
# |
| 241 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 242 |
# vlan configuration 101 |
| 243 |
# member evpn-instance 101 vni 10101 |
| 244 |
# vlan configuration 201 |
| 245 |
# member evpn-instance 201 vni 10201 |
| 246 |
|
| 247 |
|
| 248 |
- name: Merge provided configuration with device configuration |
| 249 |
cisco.ios.ios_vlans: |
| 250 |
config: |
| 251 |
- vlan_id: 102 |
| 252 |
member: |
| 253 |
vni: 10102 |
| 254 |
evi: 102 |
| 255 |
- vlan_id: 901 |
| 256 |
member: |
| 257 |
vni: 50901 |
| 258 |
state: merged |
| 259 |
|
| 260 |
# After state: |
| 261 |
# ------------ |
| 262 |
# |
| 263 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 264 |
# vlan configuration 101 |
| 265 |
# member evpn-instance 101 vni 10101 |
| 266 |
# vlan configuration 102 |
| 267 |
# member evpn-instance 102 vni 10102 |
| 268 |
# vlan configuration 201 |
| 269 |
# member evpn-instance 201 vni 10201 |
| 270 |
# vlan configuration 901 |
| 271 |
# member vni 50901 |
| 272 |
|
| 273 |
# Using overridden |
| 274 |
|
| 275 |
# Before state: |
| 276 |
# ------------- |
| 277 |
# |
| 278 |
# S1#show vlan |
| 279 |
|
| 280 |
# VLAN Name Status Ports |
| 281 |
# ---- -------------------------------- --------- ------------------------------- |
| 282 |
# 1 default active Gi0/0, Gi0/1, Gi0/2, Gi0/3 |
| 283 |
# 10 Vlan_10 active |
| 284 |
# 20 Vlan_20 active |
| 285 |
# 30 Vlan_30 suspended |
| 286 |
# 44 Vlan_44 suspended |
| 287 |
# 1002 fddi-default act/unsup |
| 288 |
# 1003 token-ring-default act/unsup |
| 289 |
# 1004 fddinet-default act/unsup |
| 290 |
# 1005 trnet-default act/unsup |
| 291 |
|
| 292 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 293 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 294 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 295 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 296 |
# 20 enet 100020 610 - - - - - 0 0 |
| 297 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 298 |
# 44 enet 100044 1500 - - - - - 0 0 |
| 299 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 300 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 301 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 302 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 303 |
|
| 304 |
# Remote SPAN VLANs |
| 305 |
# ------------------------------------------------------------------------------ |
| 306 |
|
| 307 |
|
| 308 |
# Primary Secondary Type Ports |
| 309 |
# ------- --------- ----------------- ------------------------------------------ |
| 310 |
# S1# |
| 311 |
|
| 312 |
|
| 313 |
- name: Override device configuration of all VLANs with provided configuration |
| 314 |
cisco.ios.ios_vlans: |
| 315 |
config: |
| 316 |
- name: Vlan_2020 |
| 317 |
state: active |
| 318 |
vlan_id: 20 |
| 319 |
shutdown: disabled |
| 320 |
state: overridden |
| 321 |
|
| 322 |
# Task output: |
| 323 |
# ------------ |
| 324 |
|
| 325 |
# after: |
| 326 |
# - mtu: 1500 |
| 327 |
# name: default |
| 328 |
# shutdown: disabled |
| 329 |
# state: active |
| 330 |
# vlan_id: 1 |
| 331 |
# - mtu: 1500 |
| 332 |
# name: Vlan_2020 |
| 333 |
# shutdown: disabled |
| 334 |
# state: active |
| 335 |
# vlan_id: 20 |
| 336 |
# - mtu: 1500 |
| 337 |
# name: fddi-default |
| 338 |
# shutdown: enabled |
| 339 |
# state: active |
| 340 |
# vlan_id: 1002 |
| 341 |
# - mtu: 1500 |
| 342 |
# name: token-ring-default |
| 343 |
# shutdown: enabled |
| 344 |
# state: active |
| 345 |
# vlan_id: 1003 |
| 346 |
# - mtu: 1500 |
| 347 |
# name: fddinet-default |
| 348 |
# shutdown: enabled |
| 349 |
# state: active |
| 350 |
# vlan_id: 1004 |
| 351 |
# - mtu: 1500 |
| 352 |
# name: trnet-default |
| 353 |
# shutdown: enabled |
| 354 |
# state: active |
| 355 |
# vlan_id: 1005 |
| 356 |
|
| 357 |
# before: |
| 358 |
# - mtu: 1500 |
| 359 |
# name: default |
| 360 |
# shutdown: disabled |
| 361 |
# state: active |
| 362 |
# vlan_id: 1 |
| 363 |
# - mtu: 1500 |
| 364 |
# name: Vlan_10 |
| 365 |
# shutdown: disabled |
| 366 |
# state: active |
| 367 |
# vlan_id: 10 |
| 368 |
# - mtu: 610 |
| 369 |
# name: Vlan_20 |
| 370 |
# shutdown: disabled |
| 371 |
# state: active |
| 372 |
# vlan_id: 20 |
| 373 |
# - mtu: 1500 |
| 374 |
# name: Vlan_30 |
| 375 |
# shutdown: disabled |
| 376 |
# state: suspend |
| 377 |
# vlan_id: 30 |
| 378 |
# - mtu: 1500 |
| 379 |
# name: Vlan_44 |
| 380 |
# shutdown: disabled |
| 381 |
# state: suspend |
| 382 |
# vlan_id: 44 |
| 383 |
# - mtu: 1500 |
| 384 |
# name: fddi-default |
| 385 |
# shutdown: enabled |
| 386 |
# state: active |
| 387 |
# vlan_id: 1002 |
| 388 |
# - mtu: 1500 |
| 389 |
# name: token-ring-default |
| 390 |
# shutdown: enabled |
| 391 |
# state: active |
| 392 |
# vlan_id: 1003 |
| 393 |
# - mtu: 1500 |
| 394 |
# name: fddinet-default |
| 395 |
# shutdown: enabled |
| 396 |
# state: active |
| 397 |
# vlan_id: 1004 |
| 398 |
# - mtu: 1500 |
| 399 |
# name: trnet-default |
| 400 |
# shutdown: enabled |
| 401 |
# state: active |
| 402 |
# vlan_id: 1005 |
| 403 |
|
| 404 |
# commands: |
| 405 |
# - no vlan 1 |
| 406 |
# - no vlan 10 |
| 407 |
# - no vlan 30 |
| 408 |
# - no vlan 44 |
| 409 |
# - no vlan 1002 |
| 410 |
# - no vlan 1003 |
| 411 |
# - no vlan 1004 |
| 412 |
# - no vlan 1005 |
| 413 |
# - vlan 20 |
| 414 |
# - name Vlan_2020 |
| 415 |
# - no mtu 610 |
| 416 |
# - no vlan configuration 1 |
| 417 |
# - no vlan configuration 10 |
| 418 |
# - no vlan configuration 30 |
| 419 |
# - no vlan configuration 44 |
| 420 |
# - no vlan configuration 1002 |
| 421 |
# - no vlan configuration 1003 |
| 422 |
# - no vlan configuration 1004 |
| 423 |
# - no vlan configuration 1005 |
| 424 |
|
| 425 |
# After state: |
| 426 |
# ------------ |
| 427 |
# |
| 428 |
# vios_l2#show vlan |
| 429 |
# VLAN Name Status Ports |
| 430 |
# ---- -------------------------------- --------- ------------------------------- |
| 431 |
# 1 default active Gi0/0, Gi0/1, Gi0/2, Gi0/3 |
| 432 |
# 20 Vlan_2020 active |
| 433 |
# 1002 fddi-default act/unsup |
| 434 |
# 1003 token-ring-default act/unsup |
| 435 |
# 1004 fddinet-default act/unsup |
| 436 |
# 1005 trnet-default act/unsup |
| 437 |
|
| 438 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 439 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 440 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 441 |
# 20 enet 100020 1500 - - - - - 0 0 |
| 442 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 443 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 444 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 445 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 446 |
|
| 447 |
# Remote SPAN VLANs |
| 448 |
# ------------------------------------------------------------------------------ |
| 449 |
|
| 450 |
|
| 451 |
# Primary Secondary Type Ports |
| 452 |
# ------- --------- ----------------- ------------------------------------------ |
| 453 |
|
| 454 |
# Using purged |
| 455 |
|
| 456 |
# Before state: |
| 457 |
# ------------- |
| 458 |
# |
| 459 |
# S1#show vlan |
| 460 |
|
| 461 |
# VLAN Name Status Ports |
| 462 |
# ---- -------------------------------- --------- ------------------------------- |
| 463 |
# 1 default active Gi0/0, Gi0/1, Gi0/2, Gi0/3 |
| 464 |
# 20 Vlan_2020 active |
| 465 |
# 1002 fddi-default act/unsup |
| 466 |
# 1003 token-ring-default act/unsup |
| 467 |
# 1004 fddinet-default act/unsup |
| 468 |
# 1005 trnet-default act/unsup |
| 469 |
|
| 470 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 471 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 472 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 473 |
# 20 enet 100020 1500 - - - - - 0 0 |
| 474 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 475 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 476 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 477 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 478 |
|
| 479 |
# Remote SPAN VLANs |
| 480 |
# ------------------------------------------------------------------------------ |
| 481 |
|
| 482 |
|
| 483 |
# Primary Secondary Type Ports |
| 484 |
# ------- --------- ----------------- ------------------------------------------ |
| 485 |
|
| 486 |
# S1#show running-config | section ^vlan configuration .+ |
| 487 |
# vlan configuration 20 |
| 488 |
|
| 489 |
|
| 490 |
- name: Purge all vlans configuration |
| 491 |
cisco.ios.ios_vlans: |
| 492 |
config: |
| 493 |
state: purged |
| 494 |
|
| 495 |
# Task output: |
| 496 |
# ------------ |
| 497 |
|
| 498 |
# after: |
| 499 |
# - mtu: 1500 |
| 500 |
# name: default |
| 501 |
# shutdown: disabled |
| 502 |
# state: active |
| 503 |
# vlan_id: 1 |
| 504 |
# - mtu: 1500 |
| 505 |
# name: fddi-default |
| 506 |
# shutdown: enabled |
| 507 |
# state: active |
| 508 |
# vlan_id: 1002 |
| 509 |
# - mtu: 1500 |
| 510 |
# name: token-ring-default |
| 511 |
# shutdown: enabled |
| 512 |
# state: active |
| 513 |
# vlan_id: 1003 |
| 514 |
# - mtu: 1500 |
| 515 |
# name: fddinet-default |
| 516 |
# shutdown: enabled |
| 517 |
# state: active |
| 518 |
# vlan_id: 1004 |
| 519 |
# - mtu: 1500 |
| 520 |
# name: trnet-default |
| 521 |
# shutdown: enabled |
| 522 |
# state: active |
| 523 |
# vlan_id: 1005 |
| 524 |
|
| 525 |
# before: |
| 526 |
# - mtu: 1500 |
| 527 |
# name: default |
| 528 |
# shutdown: disabled |
| 529 |
# state: active |
| 530 |
# vlan_id: 1 |
| 531 |
# - mtu: 1500 |
| 532 |
# name: Vlan_2020 |
| 533 |
# shutdown: disabled |
| 534 |
# state: active |
| 535 |
# vlan_id: 20 |
| 536 |
# - mtu: 1500 |
| 537 |
# name: fddi-default |
| 538 |
# shutdown: enabled |
| 539 |
# state: active |
| 540 |
# vlan_id: 1002 |
| 541 |
# - mtu: 1500 |
| 542 |
# name: token-ring-default |
| 543 |
# shutdown: enabled |
| 544 |
# state: active |
| 545 |
# vlan_id: 1003 |
| 546 |
# - mtu: 1500 |
| 547 |
# name: fddinet-default |
| 548 |
# shutdown: enabled |
| 549 |
# state: active |
| 550 |
# vlan_id: 1004 |
| 551 |
# - mtu: 1500 |
| 552 |
# name: trnet-default |
| 553 |
# shutdown: enabled |
| 554 |
# state: active |
| 555 |
# vlan_id: 1005 |
| 556 |
|
| 557 |
# commands: |
| 558 |
# - no vlan 1 |
| 559 |
# - no vlan 20 |
| 560 |
# - no vlan 1002 |
| 561 |
# - no vlan 1003 |
| 562 |
# - no vlan 1004 |
| 563 |
# - no vlan 1005 |
| 564 |
# - no vlan configuration 1 |
| 565 |
# - no vlan configuration 20 |
| 566 |
# - no vlan configuration 1002 |
| 567 |
# - no vlan configuration 1003 |
| 568 |
# - no vlan configuration 1004 |
| 569 |
# - no vlan configuration 1005 |
| 570 |
|
| 571 |
# After state: |
| 572 |
# ------------ |
| 573 |
# |
| 574 |
# S1#show vlan |
| 575 |
|
| 576 |
# VLAN Name Status Ports |
| 577 |
# ---- -------------------------------- --------- ------------------------------- |
| 578 |
# 1 default active Gi0/0, Gi0/1, Gi0/2, Gi0/3 |
| 579 |
# 1002 fddi-default act/unsup |
| 580 |
# 1003 token-ring-default act/unsup |
| 581 |
# 1004 fddinet-default act/unsup |
| 582 |
# 1005 trnet-default act/unsup |
| 583 |
|
| 584 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 585 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 586 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 587 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 588 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 589 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 590 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 591 |
|
| 592 |
# Remote SPAN VLANs |
| 593 |
# ------------------------------------------------------------------------------ |
| 594 |
|
| 595 |
|
| 596 |
# Primary Secondary Type Ports |
| 597 |
# ------- --------- ----------------- ------------------------------------------ |
| 598 |
|
| 599 |
# S1#show running-config | section ^vlan configuration .+ |
| 600 |
# S1# |
| 601 |
|
| 602 |
|
| 603 |
# Using replaced |
| 604 |
|
| 605 |
# Before state: |
| 606 |
# ------------- |
| 607 |
# |
| 608 |
# vios_l2#show vlan |
| 609 |
# VLAN Name Status Ports |
| 610 |
# ---- -------------------------------- --------- ------------------------------- |
| 611 |
# 1 default active Gi0/1, Gi0/2 |
| 612 |
# 10 vlan_10 active |
| 613 |
# 20 vlan_20 act/lshut |
| 614 |
# 30 vlan_30 sus/lshut |
| 615 |
# 1002 fddi-default act/unsup |
| 616 |
# 1003 token-ring-default act/unsup |
| 617 |
# 1004 fddinet-default act/unsup |
| 618 |
# 1005 trnet-default act/unsup |
| 619 |
# |
| 620 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 621 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 622 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 623 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 624 |
# 20 enet 100020 610 - - - - - 0 0 |
| 625 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 626 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 627 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 628 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 629 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 630 |
# |
| 631 |
# Remote SPAN VLANs |
| 632 |
# ------------------------------------------------------------------------------ |
| 633 |
# 10 |
| 634 |
|
| 635 |
- name: Replaces device configuration of listed VLANs with provided configuration |
| 636 |
cisco.ios.ios_vlans: |
| 637 |
config: |
| 638 |
- vlan_id: 20 |
| 639 |
name: Test_VLAN20 |
| 640 |
mtu: 700 |
| 641 |
shutdown: disabled |
| 642 |
- vlan_id: 50 |
| 643 |
name: pvlan-isolated |
| 644 |
private_vlan: |
| 645 |
type: isolated |
| 646 |
- vlan_id: 60 |
| 647 |
name: pvlan-community |
| 648 |
private_vlan: |
| 649 |
type: community |
| 650 |
- vlan_id: 70 |
| 651 |
name: pvlan-primary |
| 652 |
private_vlan: |
| 653 |
type: primary |
| 654 |
associated: |
| 655 |
- 50 |
| 656 |
- 60 |
| 657 |
|
| 658 |
state: replaced |
| 659 |
|
| 660 |
# After state: |
| 661 |
# ------------ |
| 662 |
# |
| 663 |
# vios_l2#sh vlan |
| 664 |
# VLAN Name Status Ports |
| 665 |
# ---- -------------------------------- --------- ------------------------------- |
| 666 |
# 1 default active Gi0/0, Gi0/1, Gi0/2, Gi0/3 |
| 667 |
# 10 Vlan_10 active |
| 668 |
# 20 Test_VLAN20 active |
| 669 |
# 50 pvlan-isolated active |
| 670 |
# 60 pvlan-community active |
| 671 |
# 70 pvlan-primary active |
| 672 |
# 1002 fddi-default act/unsup |
| 673 |
# 1003 token-ring-default act/unsup |
| 674 |
# 1004 fddinet-default act/unsup |
| 675 |
# 1005 trnet-default act/unsup |
| 676 |
# |
| 677 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 678 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 679 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 680 |
# 10 enet 100010 1000 - - - - - 0 0 |
| 681 |
# 20 enet 100020 700 - - - - - 0 0 |
| 682 |
# 50 enet 100050 1500 - - - - - 0 0 |
| 683 |
# 60 enet 100051 1500 - - - - - 0 0 |
| 684 |
# 70 enet 100059 1500 - - - - - 0 0 |
| 685 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 686 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 687 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 688 |
# |
| 689 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 690 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 691 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 692 |
# |
| 693 |
# Remote SPAN VLANs |
| 694 |
# ------------------------------------------------------------------------------ |
| 695 |
# |
| 696 |
# |
| 697 |
# Primary Secondary Type Ports |
| 698 |
# ------- --------- ----------------- ------------------------------------------ |
| 699 |
# 70 50 isolated |
| 700 |
# 70 60 community |
| 701 |
|
| 702 |
# Using deleted |
| 703 |
|
| 704 |
# Before state: |
| 705 |
# ------------- |
| 706 |
# |
| 707 |
# vios_l2#show vlan |
| 708 |
# VLAN Name Status Ports |
| 709 |
# ---- -------------------------------- --------- ------------------------------- |
| 710 |
# 1 default active Gi0/1, Gi0/2 |
| 711 |
# 10 vlan_10 active |
| 712 |
# 20 vlan_20 act/lshut |
| 713 |
# 30 vlan_30 sus/lshut |
| 714 |
# 1002 fddi-default act/unsup |
| 715 |
# 1003 token-ring-default act/unsup |
| 716 |
# 1004 fddinet-default act/unsup |
| 717 |
# 1005 trnet-default act/unsup |
| 718 |
# |
| 719 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 720 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 721 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 722 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 723 |
# 20 enet 100020 610 - - - - - 0 0 |
| 724 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 725 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 726 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 727 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 728 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 729 |
# |
| 730 |
# Remote SPAN VLANs |
| 731 |
# ------------------------------------------------------------------------------ |
| 732 |
# 10 |
| 733 |
|
| 734 |
- name: Delete attributes of given VLANs |
| 735 |
cisco.ios.ios_vlans: |
| 736 |
config: |
| 737 |
- vlan_id: 10 |
| 738 |
- vlan_id: 20 |
| 739 |
state: deleted |
| 740 |
|
| 741 |
# After state: |
| 742 |
# ------------- |
| 743 |
# |
| 744 |
# vios_l2#show vlan |
| 745 |
# VLAN Name Status Ports |
| 746 |
# ---- -------------------------------- --------- ------------------------------- |
| 747 |
# 1 default active Gi0/1, Gi0/2 |
| 748 |
# 30 vlan_30 sus/lshut |
| 749 |
# 1002 fddi-default act/unsup |
| 750 |
# 1003 token-ring-default act/unsup |
| 751 |
# 1004 fddinet-default act/unsup |
| 752 |
# 1005 trnet-default act/unsup |
| 753 |
# |
| 754 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 755 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 756 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 757 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 758 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 759 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 760 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 761 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 762 |
|
| 763 |
# Using deleted |
| 764 |
|
| 765 |
# Before state: |
| 766 |
# ------------- |
| 767 |
# |
| 768 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 769 |
# vlan configuration 101 |
| 770 |
# member evpn-instance 101 vni 10101 |
| 771 |
# vlan configuration 102 |
| 772 |
# member evpn-instance 102 vni 10102 |
| 773 |
# vlan configuration 201 |
| 774 |
# member evpn-instance 201 vni 10201 |
| 775 |
# vlan configuration 901 |
| 776 |
# member vni 50901 |
| 777 |
|
| 778 |
- name: Delete attributes of given VLANs |
| 779 |
cisco.ios.ios_vlans: |
| 780 |
config: |
| 781 |
- vlan_id: 101 |
| 782 |
state: deleted |
| 783 |
|
| 784 |
# After state: |
| 785 |
# ------------- |
| 786 |
# |
| 787 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 788 |
# vlan configuration 101 |
| 789 |
# vlan configuration 102 |
| 790 |
# member evpn-instance 102 vni 10102 |
| 791 |
# vlan configuration 201 |
| 792 |
# member evpn-instance 201 vni 10201 |
| 793 |
# vlan configuration 901 |
| 794 |
# member vni 50901 |
| 795 |
|
| 796 |
# Using Deleted without any config passed |
| 797 |
# "(NOTE: This will delete all of configured vlans attributes)" |
| 798 |
|
| 799 |
# Before state: |
| 800 |
# ------------- |
| 801 |
# |
| 802 |
# vios_l2#show vlan |
| 803 |
# VLAN Name Status Ports |
| 804 |
# ---- -------------------------------- --------- ------------------------------- |
| 805 |
# 1 default active Gi0/1, Gi0/2 |
| 806 |
# 10 vlan_10 active |
| 807 |
# 20 vlan_20 act/lshut |
| 808 |
# 30 vlan_30 sus/lshut |
| 809 |
# 1002 fddi-default act/unsup |
| 810 |
# 1003 token-ring-default act/unsup |
| 811 |
# 1004 fddinet-default act/unsup |
| 812 |
# 1005 trnet-default act/unsup |
| 813 |
# |
| 814 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 815 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 816 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 817 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 818 |
# 20 enet 100020 610 - - - - - 0 0 |
| 819 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 820 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 821 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 822 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 823 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 824 |
# |
| 825 |
# Remote SPAN VLANs |
| 826 |
# ------------------------------------------------------------------------------ |
| 827 |
# 10 |
| 828 |
|
| 829 |
- name: Delete attributes of ALL VLANs |
| 830 |
cisco.ios.ios_vlans: |
| 831 |
state: deleted |
| 832 |
|
| 833 |
# After state: |
| 834 |
# ------------- |
| 835 |
# |
| 836 |
# vios_l2#show vlan |
| 837 |
# VLAN Name Status Ports |
| 838 |
# ---- -------------------------------- --------- ------------------------------- |
| 839 |
# 1 default active Gi0/1, Gi0/2 |
| 840 |
# 1002 fddi-default act/unsup |
| 841 |
# 1003 token-ring-default act/unsup |
| 842 |
# 1004 fddinet-default act/unsup |
| 843 |
# 1005 trnet-default act/unsup |
| 844 |
# |
| 845 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 846 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 847 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 848 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 849 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 850 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 851 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 852 |
|
| 853 |
# Using Deleted without any config passed |
| 854 |
# "(NOTE: This will delete all of configured vlans attributes)" |
| 855 |
|
| 856 |
# Before state: |
| 857 |
# ------------- |
| 858 |
# |
| 859 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 860 |
# vlan configuration 101 |
| 861 |
# member evpn-instance 101 vni 10101 |
| 862 |
# vlan configuration 102 |
| 863 |
# member evpn-instance 102 vni 10102 |
| 864 |
# vlan configuration 201 |
| 865 |
# member evpn-instance 201 vni 10201 |
| 866 |
# vlan configuration 202 |
| 867 |
# member evpn-instance 202 vni 10202 |
| 868 |
# vlan configuration 901 |
| 869 |
# member vni 50901 |
| 870 |
|
| 871 |
- name: Delete attributes of ALL VLANs |
| 872 |
cisco.ios.ios_vlans: |
| 873 |
state: deleted |
| 874 |
|
| 875 |
# After state: |
| 876 |
# ------------- |
| 877 |
# |
| 878 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 879 |
# no vlan configuration 101 |
| 880 |
# no vlan configuration 102 |
| 881 |
# no vlan configuration 201 |
| 882 |
# no vlan configuration 202 |
| 883 |
# no vlan configuration 901 |
| 884 |
# no vlan configuration 902 |
| 885 |
|
| 886 |
# Using gathered, vlan configuration only |
| 887 |
|
| 888 |
# Before state: |
| 889 |
# ------------- |
| 890 |
# |
| 891 |
# Leaf-01#show run nve | sec ^vlan configuration |
| 892 |
# vlan configuration 101 |
| 893 |
# member evpn-instance 101 vni 10101 |
| 894 |
# vlan configuration 102 |
| 895 |
# member evpn-instance 102 vni 10102 |
| 896 |
# vlan configuration 201 |
| 897 |
# member evpn-instance 201 vni 10201 |
| 898 |
# vlan configuration 202 |
| 899 |
# member evpn-instance 202 vni 10202 |
| 900 |
# vlan configuration 901 |
| 901 |
# member vni 50901 |
| 902 |
|
| 903 |
- name: Gather listed vlans with provided configurations |
| 904 |
cisco.ios.ios_vlans: |
| 905 |
state: gathered |
| 906 |
|
| 907 |
# Module Execution Result: |
| 908 |
# ------------------------ |
| 909 |
# |
| 910 |
# gathered = [ |
| 911 |
# { |
| 912 |
# "member": { |
| 913 |
# "evi": 101, |
| 914 |
# "vni": 10101 |
| 915 |
# }, |
| 916 |
# "vlan_id": 101 |
| 917 |
# }, |
| 918 |
# { |
| 919 |
# "member": { |
| 920 |
# "evi": 102, |
| 921 |
# "vni": 10102 |
| 922 |
# }, |
| 923 |
# "vlan_id": 102 |
| 924 |
# }, |
| 925 |
# { |
| 926 |
# "member": { |
| 927 |
# "evi": 201, |
| 928 |
# "vni": 10201 |
| 929 |
# }, |
| 930 |
# "vlan_id": 201 |
| 931 |
# }, |
| 932 |
# { |
| 933 |
# "member": { |
| 934 |
# "evi": 202, |
| 935 |
# "vni": 10202 |
| 936 |
# }, |
| 937 |
# "vlan_id": 202 |
| 938 |
# }, |
| 939 |
# { |
| 940 |
# "member": { |
| 941 |
# "vni": 50901 |
| 942 |
# }, |
| 943 |
# "vlan_id": 901 |
| 944 |
# }, |
| 945 |
# { |
| 946 |
# "member": { |
| 947 |
# "vni": 50902 |
| 948 |
# }, |
| 949 |
# "vlan_id": 902 |
| 950 |
# } |
| 951 |
# ] |
| 952 |
|
| 953 |
# Using Rendered |
| 954 |
|
| 955 |
- name: Render the commands for provided configuration |
| 956 |
cisco.ios.ios_vlans: |
| 957 |
config: |
| 958 |
- name: Vlan_10 |
| 959 |
vlan_id: 10 |
| 960 |
state: active |
| 961 |
shutdown: disabled |
| 962 |
remote_span: true |
| 963 |
- name: Vlan_20 |
| 964 |
vlan_id: 20 |
| 965 |
mtu: 610 |
| 966 |
state: active |
| 967 |
shutdown: enabled |
| 968 |
- name: Vlan_30 |
| 969 |
vlan_id: 30 |
| 970 |
state: suspend |
| 971 |
shutdown: enabled |
| 972 |
state: rendered |
| 973 |
|
| 974 |
# Module Execution Result: |
| 975 |
# ------------------------ |
| 976 |
# |
| 977 |
# "rendered": [ |
| 978 |
# "vlan 10", |
| 979 |
# "name Vlan_10", |
| 980 |
# "state active", |
| 981 |
# "remote-span", |
| 982 |
# "no shutdown", |
| 983 |
# "vlan 20", |
| 984 |
# "name Vlan_20", |
| 985 |
# "state active", |
| 986 |
# "mtu 610", |
| 987 |
# "shutdown", |
| 988 |
# "vlan 30", |
| 989 |
# "name Vlan_30", |
| 990 |
# "state suspend", |
| 991 |
# "shutdown" |
| 992 |
# ] |
| 993 |
|
| 994 |
# Using Rendered |
| 995 |
|
| 996 |
- name: Render the commands for provided configuration |
| 997 |
cisco.ios.ios_vlans: |
| 998 |
config: |
| 999 |
- vlan_id: 101 |
| 1000 |
member: |
| 1001 |
vni: 10101 |
| 1002 |
evi: 101 |
| 1003 |
- vlan_id: 102 |
| 1004 |
member: |
| 1005 |
vni: 10102 |
| 1006 |
evi: 102 |
| 1007 |
state: rendered |
| 1008 |
|
| 1009 |
# Module Execution Result: |
| 1010 |
# ------------------------ |
| 1011 |
# |
| 1012 |
# "rendered": [ |
| 1013 |
# "vlan configuration 101", |
| 1014 |
# "member evpn-instance 101 vni 10101", |
| 1015 |
# "vlan configuration 102", |
| 1016 |
# "member evpn-instance 102 vni 10102" |
| 1017 |
# ] |
| 1018 |
|
| 1019 |
# Using Parsed |
| 1020 |
|
| 1021 |
# File: parsed.cfg |
| 1022 |
# ---------------- |
| 1023 |
# |
| 1024 |
# VLAN Name Status Ports |
| 1025 |
# ---- -------------------------------- --------- ------------------------------- |
| 1026 |
# 1 default active Gi0/1, Gi0/2 |
| 1027 |
# 10 vlan_10 active |
| 1028 |
# 20 vlan_20 act/lshut |
| 1029 |
# 30 vlan_30 sus/lshut |
| 1030 |
# 1002 fddi-default act/unsup |
| 1031 |
# 1003 token-ring-default act/unsup |
| 1032 |
# 1004 fddinet-default act/unsup |
| 1033 |
# 1005 trnet-default act/unsup |
| 1034 |
# |
| 1035 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 1036 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 1037 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 1038 |
# 10 enet 100010 1500 - - - - - 0 0 |
| 1039 |
# 20 enet 100020 1500 - - - - - 0 0 |
| 1040 |
# 30 enet 100030 1500 - - - - - 0 0 |
| 1041 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 1042 |
# 1003 tr 101003 1500 - - - - - 0 0 |
| 1043 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 1044 |
# 1005 trnet 101005 1500 - - - ibm - 0 0 |
| 1045 |
|
| 1046 |
- name: Parse the commands for provided configuration |
| 1047 |
cisco.ios.ios_vlans: |
| 1048 |
running_config: "{{ lookup('file', './parsed.cfg') }}" |
| 1049 |
state: parsed |
| 1050 |
|
| 1051 |
# Module Execution Result: |
| 1052 |
# ------------------------ |
| 1053 |
# |
| 1054 |
# "parsed": [ |
| 1055 |
# { |
| 1056 |
# "mtu": 1500, |
| 1057 |
# "name": "default", |
| 1058 |
# "shutdown": "disabled", |
| 1059 |
# "state": "active", |
| 1060 |
# "vlan_id": 1 |
| 1061 |
# }, |
| 1062 |
# { |
| 1063 |
# "mtu": 1500, |
| 1064 |
# "name": "vlan_10", |
| 1065 |
# "shutdown": "disabled", |
| 1066 |
# "state": "active", |
| 1067 |
# "vlan_id": 10 |
| 1068 |
# }, |
| 1069 |
# { |
| 1070 |
# "mtu": 1500, |
| 1071 |
# "name": "vlan_20", |
| 1072 |
# "shutdown": "enabled", |
| 1073 |
# "state": "active", |
| 1074 |
# "vlan_id": 20 |
| 1075 |
# }, |
| 1076 |
# { |
| 1077 |
# "mtu": 1500, |
| 1078 |
# "name": "vlan_30", |
| 1079 |
# "shutdown": "enabled", |
| 1080 |
# "state": "suspend", |
| 1081 |
# "vlan_id": 30 |
| 1082 |
# }, |
| 1083 |
# { |
| 1084 |
# "mtu": 1500, |
| 1085 |
# "name": "fddi-default", |
| 1086 |
# "shutdown": "enabled", |
| 1087 |
# "state": "active", |
| 1088 |
# "vlan_id": 1002 |
| 1089 |
# }, |
| 1090 |
# { |
| 1091 |
# "mtu": 1500, |
| 1092 |
# "name": "token-ring-default", |
| 1093 |
# "shutdown": "enabled", |
| 1094 |
# "state": "active", |
| 1095 |
# "vlan_id": 1003 |
| 1096 |
# }, |
| 1097 |
# { |
| 1098 |
# "mtu": 1500, |
| 1099 |
# "name": "fddinet-default", |
| 1100 |
# "shutdown": "enabled", |
| 1101 |
# "state": "active", |
| 1102 |
# "vlan_id": 1004 |
| 1103 |
# }, |
| 1104 |
# { |
| 1105 |
# "mtu": 1500, |
| 1106 |
# "name": "trnet-default", |
| 1107 |
# "shutdown": "enabled", |
| 1108 |
# "state": "active", |
| 1109 |
# "vlan_id": 1005 |
| 1110 |
# } |
| 1111 |
# ] |
| 1112 |
|
| 1113 |
# Using Parsed Vlan configuration only |
| 1114 |
|
| 1115 |
# File: parsed.cfg |
| 1116 |
# ---------------- |
| 1117 |
# |
| 1118 |
# vlan configuration 101 |
| 1119 |
# member evpn-instance 101 vni 10101 |
| 1120 |
# vlan configuration 102 |
| 1121 |
# member evpn-instance 102 vni 10102 |
| 1122 |
# vlan configuration 901 |
| 1123 |
# member vni 50901 |
| 1124 |
|
| 1125 |
- name: Parse the commands for provided configuration |
| 1126 |
cisco.ios.ios_vlans: |
| 1127 |
running_config: "{{ lookup('file', './parsed.cfg') }}" |
| 1128 |
state: parsed |
| 1129 |
|
| 1130 |
# Module Execution Result: |
| 1131 |
# ------------------------ |
| 1132 |
# |
| 1133 |
# "parsed": [ |
| 1134 |
# { |
| 1135 |
# "member": { |
| 1136 |
# "evi": 101, |
| 1137 |
# "vni": 10101 |
| 1138 |
# }, |
| 1139 |
# "vlan_id": 101 |
| 1140 |
# }, |
| 1141 |
# { |
| 1142 |
# "member": { |
| 1143 |
# "evi": 102, |
| 1144 |
# "vni": 10102 |
| 1145 |
# }, |
| 1146 |
# "vlan_id": 102 |
| 1147 |
# }, |
| 1148 |
# { |
| 1149 |
# "member": { |
| 1150 |
# "vni": 50901 |
| 1151 |
# }, |
| 1152 |
# "vlan_id": 901 |
| 1153 |
# } |
| 1154 |
# ] |
| 1155 |
|
| 1156 |
# Using Parsed, Vlan and vlan configuration |
| 1157 |
|
| 1158 |
# File: parsed.cfg |
| 1159 |
# ---------------- |
| 1160 |
# |
| 1161 |
# VLAN Name Status Ports |
| 1162 |
# ---- -------------------------------- --------- ------------------------------- |
| 1163 |
# 1 default active Gi0/1, Gi0/2 |
| 1164 |
# 101 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12 |
| 1165 |
# Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21 |
| 1166 |
# Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30 |
| 1167 |
# Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39 |
| 1168 |
# Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48 |
| 1169 |
# 150 VLAN0150 active |
| 1170 |
# 888 a_very_long_vlan_name_a_very_long_vlan_name |
| 1171 |
# active |
| 1172 |
# 1002 fddi-default act/unsup |
| 1173 |
# 1003 trcrf-default act/unsup |
| 1174 |
# 1004 fddinet-default act/unsup |
| 1175 |
# 1005 trbrf-default act/unsup |
| 1176 |
# |
| 1177 |
# VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 |
| 1178 |
# ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ |
| 1179 |
# 1 enet 100001 1500 - - - - - 0 0 |
| 1180 |
# 101 enet 100101 610 - - - - - 0 0 |
| 1181 |
# 150 enet 100150 1500 - - - - - 0 0 |
| 1182 |
# 888 enet 100888 1500 - - - - - 0 0 |
| 1183 |
# 1002 fddi 101002 1500 - - - - - 0 0 |
| 1184 |
# 1003 trcrf 101003 4472 1005 3276 - - srb 0 0 |
| 1185 |
# 1004 fdnet 101004 1500 - - - ieee - 0 0 |
| 1186 |
# 1005 trbrf 101005 4472 - - 15 ibm - 0 0 |
| 1187 |
# |
| 1188 |
# |
| 1189 |
# VLAN AREHops STEHops Backup CRF |
| 1190 |
# ---- ------- ------- ---------- |
| 1191 |
# 1003 7 7 off |
| 1192 |
# |
| 1193 |
# Remote SPAN VLANs |
| 1194 |
# ------------------------------------------------------------------------------ |
| 1195 |
# 150 |
| 1196 |
# |
| 1197 |
# Primary Secondary Type Ports |
| 1198 |
# ------- --------- ----------------- ------------------------------------------ |
| 1199 |
# |
| 1200 |
# vlan configuration 101 |
| 1201 |
# member evpn-instance 101 vni 10101 |
| 1202 |
# vlan configuration 102 |
| 1203 |
# member evpn-instance 102 vni 10102 |
| 1204 |
# vlan configuration 901 |
| 1205 |
# member vni 50901 |
| 1206 |
|
| 1207 |
- name: Parse the commands for provided configuration |
| 1208 |
cisco.ios.ios_vlans: |
| 1209 |
running_config: "{{ lookup('file', './parsed.cfg') }}" |
| 1210 |
state: parsed |
| 1211 |
|
| 1212 |
# Module Execution Result: |
| 1213 |
# ------------------------ |
| 1214 |
# |
| 1215 |
# "parsed": [ |
| 1216 |
# { |
| 1217 |
# "name": "default", |
| 1218 |
# "vlan_id": 1, |
| 1219 |
# "state": "active", |
| 1220 |
# "shutdown": "disabled", |
| 1221 |
# "mtu": 1500, |
| 1222 |
# }, |
| 1223 |
# { |
| 1224 |
# "name": "RemoteIsInMyName", |
| 1225 |
# "vlan_id": 101, |
| 1226 |
# "state": "active", |
| 1227 |
# "shutdown": "enabled", |
| 1228 |
# "mtu": 610, |
| 1229 |
# "member": {"evi": 101, "vni": 10101}, |
| 1230 |
# }, |
| 1231 |
# { |
| 1232 |
# "name": "VLAN0150", |
| 1233 |
# "vlan_id": 150, |
| 1234 |
# "state": "active", |
| 1235 |
# "shutdown": "disabled", |
| 1236 |
# "mtu": 1500, |
| 1237 |
# "remote_span": True, |
| 1238 |
# }, |
| 1239 |
# { |
| 1240 |
# "name": "a_very_long_vlan_name_a_very_long_vlan_name", |
| 1241 |
# "vlan_id": 888, |
| 1242 |
# "state": "active", |
| 1243 |
# "shutdown": "disabled", |
| 1244 |
# "mtu": 1500, |
| 1245 |
# }, |
| 1246 |
# { |
| 1247 |
# "name": "fddi-default", |
| 1248 |
# "vlan_id": 1002, |
| 1249 |
# "state": "active", |
| 1250 |
# "shutdown": "enabled", |
| 1251 |
# "mtu": 1500, |
| 1252 |
# }, |
| 1253 |
# { |
| 1254 |
# "name": "trcrf-default", |
| 1255 |
# "vlan_id": 1003, |
| 1256 |
# "state": "active", |
| 1257 |
# "shutdown": "enabled", |
| 1258 |
# "mtu": 4472, |
| 1259 |
# }, |
| 1260 |
# { |
| 1261 |
# "name": "fddinet-default", |
| 1262 |
# "vlan_id": 1004, |
| 1263 |
# "state": "active", |
| 1264 |
# "shutdown": "enabled", |
| 1265 |
# "mtu": 1500, |
| 1266 |
# }, |
| 1267 |
# { |
| 1268 |
# "name": "trbrf-default", |
| 1269 |
# "vlan_id": 1005, |
| 1270 |
# "state": "active", |
| 1271 |
# "shutdown": "enabled", |
| 1272 |
# "mtu": 4472, |
| 1273 |
# }, |
| 1274 |
# {"vlan_id": 102, "member": {"evi": 102, "vni": 10102}}, |
| 1275 |
# {"vlan_id": 901, "member": {"vni": 50901}}, |
| 1276 |
# ] |
| 1277 |
""" |
| 1278 |
|
| 1279 |
RETURN = """ |
| 1280 |
before: |
| 1281 |
description: The configuration prior to the module execution. |
| 1282 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 1283 |
type: dict |
| 1284 |
sample: > |
| 1285 |
This output will always be in the same format as the |
| 1286 |
module argspec. |
| 1287 |
after: |
| 1288 |
description: The resulting configuration after module execution. |
| 1289 |
returned: when changed |
| 1290 |
type: dict |
| 1291 |
sample: > |
| 1292 |
This output will always be in the same format as the |
| 1293 |
module argspec. |
| 1294 |
commands: |
| 1295 |
description: The set of commands pushed to the remote device. |
| 1296 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 1297 |
type: list |
| 1298 |
sample: |
| 1299 |
- vlan configuration 202 |
| 1300 |
- state active |
| 1301 |
- remote-span |
| 1302 |
rendered: |
| 1303 |
description: The provided configuration in the task rendered in device-native format (offline). |
| 1304 |
returned: when I(state) is C(rendered) |
| 1305 |
type: list |
| 1306 |
sample: |
| 1307 |
- vlan configuration 202 |
| 1308 |
- member evpn-instance 202 vni 10202 |
| 1309 |
- vlan 200 |
| 1310 |
gathered: |
| 1311 |
description: Facts about the network resource gathered from the remote device as structured data. |
| 1312 |
returned: when I(state) is C(gathered) |
| 1313 |
type: list |
| 1314 |
sample: > |
| 1315 |
This output will always be in the same format as the |
| 1316 |
module argspec. |
| 1317 |
parsed: |
| 1318 |
description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. |
| 1319 |
returned: when I(state) is C(parsed) |
| 1320 |
type: list |
| 1321 |
sample: > |
| 1322 |
This output will always be in the same format as the |
| 1323 |
module argspec. |
| 1324 |
""" |
| 1325 |
|
| 1326 |
from ansible.module_utils.basic import AnsibleModule |
| 1327 |
|
| 1328 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vlans.vlans import ( |
| 1329 |
VlansArgs, |
| 1330 |
) |
| 1331 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vlans.vlans import Vlans |
| 1332 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.ios import get_connection |
| 1333 |
|
| 1334 |
|
| 1335 |
def _is_l2_device(module): |
| 1336 |
"""fails module if device is L3.""" |
| 1337 |
connection = get_connection(module) |
| 1338 |
check_os_type = connection.get_device_info() |
| 1339 |
if check_os_type.get("network_os_type") == "L3": |
| 1340 |
return False |
| 1341 |
return True |
| 1342 |
|
| 1343 |
|
| 1344 |
def main(): |
| 1345 |
""" |
| 1346 |
Main entry point for module execution |
| 1347 |
|
| 1348 |
:returns: the result form module invocation |
| 1349 |
""" |
| 1350 |
module = AnsibleModule( |
| 1351 |
argument_spec=VlansArgs.argument_spec, |
| 1352 |
mutually_exclusive=[["config", "running_config"]], |
| 1353 |
required_if=[ |
| 1354 |
["state", "merged", ["config"]], |
| 1355 |
["state", "replaced", ["config"]], |
| 1356 |
["state", "overridden", ["config"]], |
| 1357 |
["state", "rendered", ["config"]], |
| 1358 |
["state", "purged", ["config"]], |
| 1359 |
["state", "parsed", ["running_config"]], |
| 1360 |
], |
| 1361 |
supports_check_mode=True, |
| 1362 |
) |
| 1363 |
|
| 1364 |
if _is_l2_device(module) or module.params.get("state") in ["rendered", "parsed"]: |
| 1365 |
result = Vlans(module).execute_module() |
| 1366 |
module.exit_json(**result) |
| 1367 |
else: |
| 1368 |
module.fail_json("""Resource VLAN is not valid for the target device.""") |
| 1369 |
|
| 1370 |
|
| 1371 |
if __name__ == "__main__": |
| 1372 |
main() |