| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright 2019 Red Hat Inc. |
| 4 |
# GNU General Public License v3.0+ |
| 5 |
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
############################################## |
| 8 |
# WARNING |
| 9 |
# |
| 10 |
# This file is auto generated by the resource |
| 11 |
# module builder playbook. |
| 12 |
# |
| 13 |
# Do not edit this file manually. |
| 14 |
# |
| 15 |
# Changes to this file will be over written |
| 16 |
# by the resource module builder. |
| 17 |
# |
| 18 |
# Changes should be made in the model used to |
| 19 |
# generate this file or in the resource module |
| 20 |
# builder template. |
| 21 |
# |
| 22 |
# |
| 23 |
############################################## |
| 24 |
|
| 25 |
""" |
| 26 |
The module file for ios_l3_interfaces |
| 27 |
""" |
| 28 |
|
| 29 |
from __future__ import absolute_import, division, print_function |
| 30 |
|
| 31 |
|
| 32 |
__metaclass__ = type |
| 33 |
|
| 34 |
|
| 35 |
DOCUMENTATION = """ |
| 36 |
module: iosxr_l3_interfaces |
| 37 |
short_description: Resource module to configure L3 interfaces. |
| 38 |
description: This module provides declarative management of Layer-3 interface on Cisco |
| 39 |
IOS-XR devices. |
| 40 |
version_added: 1.0.0 |
| 41 |
author: |
| 42 |
- Sumit Jaiswal (@justjais) |
| 43 |
- Rohit Thakur (@rohitthakur2590) |
| 44 |
notes: |
| 45 |
- This module works with connection C(network_cli). See L(the IOS-XR Platform Options,../network/user_guide/platform_iosxr.html). |
| 46 |
options: |
| 47 |
config: |
| 48 |
description: A dictionary of Layer-3 interface options |
| 49 |
type: list |
| 50 |
elements: dict |
| 51 |
suboptions: |
| 52 |
name: |
| 53 |
description: |
| 54 |
- Full name of the interface excluding any logical unit number, i.e. GigabitEthernet0/1. |
| 55 |
type: str |
| 56 |
required: true |
| 57 |
ipv4: |
| 58 |
description: |
| 59 |
- IPv4 address to be set for the Layer-3 interface mentioned in I(name) option. |
| 60 |
- The address format is <ipv4 address>/<mask>, the mask is number in range |
| 61 |
0-32 eg. 192.168.0.1/24 |
| 62 |
type: list |
| 63 |
elements: dict |
| 64 |
suboptions: |
| 65 |
address: |
| 66 |
description: |
| 67 |
- Configures the IPv4 address for Interface. |
| 68 |
type: str |
| 69 |
secondary: |
| 70 |
description: |
| 71 |
- Configures the IP address as a secondary address. |
| 72 |
type: bool |
| 73 |
ipv6: |
| 74 |
description: |
| 75 |
- IPv6 address to be set for the Layer-3 interface mentioned in I(name) option. |
| 76 |
- The address format is <ipv6 address>/<mask>, the mask is number in range |
| 77 |
0-128 eg. fd5d:12c9:2201:1::1/64 |
| 78 |
type: list |
| 79 |
elements: dict |
| 80 |
suboptions: |
| 81 |
address: |
| 82 |
description: |
| 83 |
- Configures the IPv6 address for Interface. |
| 84 |
type: str |
| 85 |
carrier_delay: |
| 86 |
description: |
| 87 |
- Delay carrier transitions. |
| 88 |
type: dict |
| 89 |
suboptions: |
| 90 |
up: |
| 91 |
description: |
| 92 |
- Delay for carrier-up event in milliseconds. |
| 93 |
type: int |
| 94 |
down: |
| 95 |
description: |
| 96 |
- Delay for carrier-down event in milliseconds. |
| 97 |
type: int |
| 98 |
dampening: |
| 99 |
description: |
| 100 |
- Enable interface dampening to reduce the effects of interface flapping. |
| 101 |
type: dict |
| 102 |
suboptions: |
| 103 |
enabled: |
| 104 |
description: |
| 105 |
- Enable or disable dampening. |
| 106 |
type: bool |
| 107 |
half_life: |
| 108 |
description: |
| 109 |
- The time in minutes after which a penalty is halved if the interface stays up. |
| 110 |
type: int |
| 111 |
reuse_threshold: |
| 112 |
description: |
| 113 |
- The penalty value below which a suppressed interface is unsuppressed. |
| 114 |
type: int |
| 115 |
suppress_threshold: |
| 116 |
description: |
| 117 |
- The penalty value above which an interface is suppressed. |
| 118 |
type: int |
| 119 |
max_suppress_time: |
| 120 |
description: |
| 121 |
- The maximum time in minutes that an interface can be suppressed. |
| 122 |
type: int |
| 123 |
restart_penalty: |
| 124 |
description: |
| 125 |
- The penalty assigned to an interface when it flaps. |
| 126 |
type: int |
| 127 |
load_interval: |
| 128 |
description: |
| 129 |
- Specify the length of time for which data is used to compute load statistics. |
| 130 |
type: int |
| 131 |
flow_control: |
| 132 |
description: |
| 133 |
- Configure flow control for the interface. |
| 134 |
type: str |
| 135 |
choices: ['ingress', 'egress', 'bidirectional'] |
| 136 |
flow: |
| 137 |
description: |
| 138 |
- Configure NetFlow monitoring on the interface. |
| 139 |
type: dict |
| 140 |
suboptions: |
| 141 |
ipv4: |
| 142 |
description: |
| 143 |
- Configure NetFlow monitoring for IPv4 traffic. |
| 144 |
type: dict |
| 145 |
suboptions: |
| 146 |
monitor: |
| 147 |
description: |
| 148 |
- Name of the flow monitor to apply. |
| 149 |
type: str |
| 150 |
sampler: |
| 151 |
description: |
| 152 |
- Name of the sampler to apply. |
| 153 |
type: str |
| 154 |
direction: |
| 155 |
description: |
| 156 |
- Direction of the flow monitoring. |
| 157 |
type: str |
| 158 |
choices: ['ingress', 'egress', 'bidirectional'] |
| 159 |
ipv6: |
| 160 |
description: |
| 161 |
- Configure NetFlow monitoring for IPv6 traffic. |
| 162 |
type: dict |
| 163 |
suboptions: |
| 164 |
monitor: |
| 165 |
description: |
| 166 |
- Name of the flow monitor to apply. |
| 167 |
type: str |
| 168 |
sampler: |
| 169 |
description: |
| 170 |
- Name of the sampler to apply. |
| 171 |
type: str |
| 172 |
direction: |
| 173 |
description: |
| 174 |
- Direction of the flow monitoring. |
| 175 |
type: str |
| 176 |
choices: ['ingress', 'egress', 'bidirectional'] |
| 177 |
running_config: |
| 178 |
description: |
| 179 |
- This option is used only with state I(parsed). |
| 180 |
- The value of this option should be the output received from the IOS-XR device |
| 181 |
by executing the command B(show running-config interface). |
| 182 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 183 |
transforms it into Ansible structured data as per the resource module's argspec |
| 184 |
and the value is then returned in the I(parsed) key within the result. |
| 185 |
type: str |
| 186 |
state: |
| 187 |
choices: |
| 188 |
- merged |
| 189 |
- replaced |
| 190 |
- overridden |
| 191 |
- deleted |
| 192 |
- parsed |
| 193 |
- rendered |
| 194 |
- gathered |
| 195 |
default: merged |
| 196 |
description: |
| 197 |
- The state of the configuration after module completion |
| 198 |
type: str |
| 199 |
""" |
| 200 |
|
| 201 |
EXAMPLES = """ |
| 202 |
# Using merged |
| 203 |
|
| 204 |
# Before state: |
| 205 |
# ------------- |
| 206 |
# |
| 207 |
# viosxr#show running-config interface |
| 208 |
# interface Loopback888 |
| 209 |
# ! |
| 210 |
# interface Loopback999 |
| 211 |
# ! |
| 212 |
# interface MgmtEth0/RP0/CPU0/0 |
| 213 |
# ipv4 address dhcp |
| 214 |
# ! |
| 215 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 216 |
# ! |
| 217 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 218 |
# ! |
| 219 |
|
| 220 |
- name: Merge provided configuration with device configuration |
| 221 |
cisco.iosxr.iosxr_l3_interfaces: |
| 222 |
config: |
| 223 |
- name: GigabitEthernet0/0/0/2 |
| 224 |
ipv4: |
| 225 |
- address: 192.168.0.1/24 |
| 226 |
- name: GigabitEthernet0/0/0/3 |
| 227 |
ipv4: |
| 228 |
- address: 192.168.2.1/24 |
| 229 |
secondary: true |
| 230 |
state: merged |
| 231 |
|
| 232 |
# Task Output |
| 233 |
# ----------- |
| 234 |
# |
| 235 |
# before: |
| 236 |
# - name: Loopback888 |
| 237 |
# - name: Loopback999 |
| 238 |
# - name: GigabitEthernet0/0/0/2 |
| 239 |
# - name: GigabitEthernet0/0/0/3 |
| 240 |
# commands: |
| 241 |
# - interface GigabitEthernet0/0/0/2 |
| 242 |
# - ipv4 address 192.168.0.1 255.255.255.0 |
| 243 |
# - interface GigabitEthernet0/0/0/3 |
| 244 |
# - ipv4 address 192.168.2.1 255.255.255.0 secondary |
| 245 |
# after: |
| 246 |
# - name: Loopback888 |
| 247 |
# - name: Loopback999 |
| 248 |
# - ipv4: |
| 249 |
# - address: 192.168.0.1/24 |
| 250 |
# name: GigabitEthernet0/0/0/2 |
| 251 |
# - ipv4: |
| 252 |
# - address: 192.168.2.1/24 |
| 253 |
# secondary: true |
| 254 |
# name: GigabitEthernet0/0/0/3 |
| 255 |
|
| 256 |
# After state: |
| 257 |
# ------------ |
| 258 |
# |
| 259 |
# viosxr#show running-config interface |
| 260 |
# interface Loopback888 |
| 261 |
# ! |
| 262 |
# interface Loopback999 |
| 263 |
# ! |
| 264 |
# interface MgmtEth0/RP0/CPU0/0 |
| 265 |
# ipv4 address dhcp |
| 266 |
# ! |
| 267 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 268 |
# ipv4 address 192.168.0.1 255.255.255.0 |
| 269 |
# ! |
| 270 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 271 |
# ipv4 address 192.168.2.1 255.255.255.0 secondary |
| 272 |
# ! |
| 273 |
|
| 274 |
# Using overridden |
| 275 |
|
| 276 |
# Before state: |
| 277 |
# ------------- |
| 278 |
# |
| 279 |
# viosxr#show running-config interface |
| 280 |
# interface Loopback888 |
| 281 |
# ! |
| 282 |
# interface Loopback999 |
| 283 |
# ! |
| 284 |
# interface MgmtEth0/RP0/CPU0/0 |
| 285 |
# ipv4 address dhcp |
| 286 |
# ! |
| 287 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 288 |
# ipv4 address 192.168.0.1 255.255.255.0 |
| 289 |
# ! |
| 290 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 291 |
# ipv4 address 192.168.2.1 255.255.255.0 secondary |
| 292 |
# ! |
| 293 |
|
| 294 |
- name: Override device configuration of all interfaces with provided configuration |
| 295 |
cisco.iosxr.iosxr_l3_interfaces: |
| 296 |
config: |
| 297 |
- name: GigabitEthernet0/0/0/3 |
| 298 |
ipv4: |
| 299 |
- address: 192.168.0.2/24 |
| 300 |
- address: 192.168.2.1/24 |
| 301 |
secondary: true |
| 302 |
state: overridden |
| 303 |
|
| 304 |
|
| 305 |
# Task Output |
| 306 |
# ----------- |
| 307 |
# |
| 308 |
# before: |
| 309 |
# - name: Loopback888 |
| 310 |
# - name: Loopback999 |
| 311 |
# - ipv4: |
| 312 |
# - address: 192.168.0.1/24 |
| 313 |
# name: GigabitEthernet0/0/0/2 |
| 314 |
# - ipv4: |
| 315 |
# - address: 192.168.2.1/24 |
| 316 |
# secondary: true |
| 317 |
# name: GigabitEthernet0/0/0/3 |
| 318 |
# commands: |
| 319 |
# - interface GigabitEthernet0/0/0/2 |
| 320 |
# - no ipv4 address |
| 321 |
# - interface GigabitEthernet0/0/0/3 |
| 322 |
# - ipv4 address 192.168.0.2 255.255.255.0 |
| 323 |
# - ipv4 address 192.168.0.1 255.255.255.0 |
| 324 |
# after: |
| 325 |
# - name: Loopback888 |
| 326 |
# - name: Loopback999 |
| 327 |
# - name: GigabitEthernet0/0/0/2 |
| 328 |
# - ipv4: |
| 329 |
# - address: 192.168.0.1/24 |
| 330 |
# - address: 192.168.2.1/24 |
| 331 |
# secondary: true |
| 332 |
# name: GigabitEthernet0/0/0/3 |
| 333 |
|
| 334 |
# After state: |
| 335 |
# ------------- |
| 336 |
# |
| 337 |
# viosxr#show running-config interface |
| 338 |
# interface Loopback888 |
| 339 |
# ! |
| 340 |
# interface Loopback999 |
| 341 |
# ! |
| 342 |
# interface MgmtEth0/RP0/CPU0/0 |
| 343 |
# ipv4 address dhcp |
| 344 |
# ! |
| 345 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 346 |
# ! |
| 347 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 348 |
# ipv4 address 192.168.0.1 255.255.255.0 |
| 349 |
# ipv4 address 192.168.2.1 255.255.255.0 secondary |
| 350 |
# ! |
| 351 |
|
| 352 |
# Using replaced |
| 353 |
|
| 354 |
# Before state: |
| 355 |
# ------------- |
| 356 |
# |
| 357 |
# viosxr#show running-config interface |
| 358 |
# interface Loopback888 |
| 359 |
# ! |
| 360 |
# interface Loopback999 |
| 361 |
# ! |
| 362 |
# interface MgmtEth0/RP0/CPU0/0 |
| 363 |
# ipv4 address dhcp |
| 364 |
# ! |
| 365 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 366 |
# ! |
| 367 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 368 |
# ipv4 address 192.168.0.1 255.255.255.0 |
| 369 |
# ipv4 address 192.168.2.1 255.255.255.0 secondary |
| 370 |
# ! |
| 371 |
|
| 372 |
- name: >- |
| 373 |
Replaces device configuration of listed interfaces with provided |
| 374 |
configuration |
| 375 |
cisco.iosxr.iosxr_l3_interfaces: |
| 376 |
config: |
| 377 |
- name: GigabitEthernet0/0/0/3 |
| 378 |
ipv6: |
| 379 |
- address: 'fd5d:12c9:2201:1::1/64' |
| 380 |
- name: GigabitEthernet0/0/0/2 |
| 381 |
ipv4: |
| 382 |
- address: 192.168.0.2/24 |
| 383 |
state: replaced |
| 384 |
|
| 385 |
|
| 386 |
# Task Output |
| 387 |
# ----------- |
| 388 |
# |
| 389 |
# before: |
| 390 |
# - name: Loopback888 |
| 391 |
# - name: Loopback999 |
| 392 |
# - name: GigabitEthernet0/0/0/2 |
| 393 |
# - ipv4: |
| 394 |
# - address: 192.168.0.1/24 |
| 395 |
# - address: 192.168.2.1/24 |
| 396 |
# secondary: true |
| 397 |
# name: GigabitEthernet0/0/0/3 |
| 398 |
# commands: |
| 399 |
# - interface GigabitEthernet0/0/0/3 |
| 400 |
# - no ipv4 address |
| 401 |
# - ipv6 address fd5d:12c9:2201:1::1/64 |
| 402 |
# - interface GigabitEthernet0/0/0/2 |
| 403 |
# - ipv4 address 192.168.0.2 255.255.255.0 |
| 404 |
# after: |
| 405 |
# - name: Loopback888 |
| 406 |
# - name: Loopback999 |
| 407 |
# - ipv4: |
| 408 |
# - address: 192.168.0.2/24 |
| 409 |
# name: GigabitEthernet0/0/0/2 |
| 410 |
# - ipv6: |
| 411 |
# - address: fd5d:12c9:2201:1::1/64 |
| 412 |
# name: GigabitEthernet0/0/0/3 |
| 413 |
|
| 414 |
# After state: |
| 415 |
# ------------- |
| 416 |
# |
| 417 |
# viosxr#show running-config interface |
| 418 |
# interface Loopback888 |
| 419 |
# ! |
| 420 |
# interface Loopback999 |
| 421 |
# ! |
| 422 |
# interface MgmtEth0/RP0/CPU0/0 |
| 423 |
# ipv4 address dhcp |
| 424 |
# ! |
| 425 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 426 |
# ipv4 address 192.168.0.2 255.255.255.0 |
| 427 |
# ! |
| 428 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 429 |
# ipv6 address fd5d:12c9:2201:1::1/64 |
| 430 |
# ! |
| 431 |
|
| 432 |
# Using deleted |
| 433 |
|
| 434 |
# Before state: |
| 435 |
# ------------- |
| 436 |
# |
| 437 |
# viosxr#show running-config interface |
| 438 |
# interface Loopback888 |
| 439 |
# ! |
| 440 |
# interface Loopback999 |
| 441 |
# ! |
| 442 |
# interface MgmtEth0/RP0/CPU0/0 |
| 443 |
# ipv4 address dhcp |
| 444 |
# ! |
| 445 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 446 |
# ipv4 address 192.168.0.2 255.255.255.0 |
| 447 |
# ! |
| 448 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 449 |
# ipv6 address fd5d:12c9:2201:1::1/64 |
| 450 |
# ! |
| 451 |
|
| 452 |
- name: Delete attributes for interfaces (This won't delete the interface itself) |
| 453 |
cisco.iosxr.iosxr_l3_interfaces: |
| 454 |
config: |
| 455 |
- name: GigabitEthernet0/0/0/3 |
| 456 |
- name: GigabitEthernet0/0/0/4 |
| 457 |
- name: GigabitEthernet0/0/0/3.700 |
| 458 |
state: deleted |
| 459 |
|
| 460 |
|
| 461 |
# Task Output |
| 462 |
# ----------- |
| 463 |
# |
| 464 |
# before: |
| 465 |
# - name: Loopback888 |
| 466 |
# - name: Loopback999 |
| 467 |
# - ipv4: |
| 468 |
# - address: 192.168.0.2/24 |
| 469 |
# name: GigabitEthernet0/0/0/2 |
| 470 |
# - ipv6: |
| 471 |
# - address: fd5d:12c9:2201:1::1/64 |
| 472 |
# name: GigabitEthernet0/0/0/3 |
| 473 |
# commands: |
| 474 |
# - interface GigabitEthernet0/0/0/3 |
| 475 |
# - no ipv6 address |
| 476 |
# after: |
| 477 |
# - name: Loopback888 |
| 478 |
# - name: Loopback999 |
| 479 |
# - ipv4: |
| 480 |
# - address: 192.168.0.2/24 |
| 481 |
# name: GigabitEthernet0/0/0/2 |
| 482 |
# - name: GigabitEthernet0/0/0/3 |
| 483 |
|
| 484 |
# After state: |
| 485 |
# ------------- |
| 486 |
# |
| 487 |
# viosxr#show running-config interface |
| 488 |
# interface Loopback888 |
| 489 |
# ! |
| 490 |
# interface Loopback999 |
| 491 |
# ! |
| 492 |
# interface MgmtEth0/RP0/CPU0/0 |
| 493 |
# ipv4 address dhcp |
| 494 |
# ! |
| 495 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 496 |
# ipv4 address 192.168.0.2 255.255.255.0 |
| 497 |
# ! |
| 498 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 499 |
# ! |
| 500 |
|
| 501 |
# Using deleted - will delete all interface configuration and not interface |
| 502 |
|
| 503 |
# Before state: |
| 504 |
# ------------- |
| 505 |
# |
| 506 |
# viosxr#show running-config interface |
| 507 |
# interface Loopback888 |
| 508 |
# ! |
| 509 |
# interface Loopback999 |
| 510 |
# ! |
| 511 |
# interface MgmtEth0/RP0/CPU0/0 |
| 512 |
# ipv4 address dhcp |
| 513 |
# ! |
| 514 |
# interface preconfigure GigabitEthernet0/0/0/1 |
| 515 |
# ipv4 address 192.168.2.1 255.255.255.0 |
| 516 |
# shutdown |
| 517 |
# ! |
| 518 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 519 |
# ipv4 address 192.168.3.1 255.255.255.0 |
| 520 |
# shutdown |
| 521 |
# ! |
| 522 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 523 |
# ipv4 address 192.168.0.2 255.255.255.0 |
| 524 |
# shutdown |
| 525 |
# ! |
| 526 |
# interface preconfigure GigabitEthernet0/0/0/3.700 |
| 527 |
# ipv4 address 192.168.0.1 255.255.255.0 |
| 528 |
# ! |
| 529 |
# interface preconfigure GigabitEthernet0/0/0/4 |
| 530 |
# ipv6 address fd5d:12c9:2201:1::1/64 |
| 531 |
# shutdown |
| 532 |
# ! |
| 533 |
|
| 534 |
- name: "Delete L3 config of all interfaces (This won't delete the interface itself)" |
| 535 |
cisco.iosxr.iosxr_l3_interfaces: |
| 536 |
state: deleted |
| 537 |
|
| 538 |
# Task Output |
| 539 |
# ----------- |
| 540 |
# |
| 541 |
# before: |
| 542 |
# - name: Loopback888 |
| 543 |
# - name: Loopback999 |
| 544 |
# - ipv4: |
| 545 |
# - address: 192.168.2.1/24 |
| 546 |
# name: GigabitEthernet0/0/0/1 |
| 547 |
# - ipv4: |
| 548 |
# - address: 192.168.3.1/24 |
| 549 |
# name: GigabitEthernet0/0/0/2 |
| 550 |
# - ipv4: |
| 551 |
# - address: 192.168.0.2/24 |
| 552 |
# name: GigabitEthernet0/0/0/3 |
| 553 |
# - ipv4: |
| 554 |
# - address: 192.168.0.1/24 |
| 555 |
# name: GigabitEthernet0/0/0/3.700 |
| 556 |
# - ipv6: |
| 557 |
# - address: fd5d:12c9:2201:1::1/64 |
| 558 |
# name: GigabitEthernet0/0/0/4 |
| 559 |
# commands: |
| 560 |
# - interface GigabitEthernet0/0/0/1 |
| 561 |
# - no ipv4 address |
| 562 |
# - interface GigabitEthernet0/0/0/2 |
| 563 |
# - no ipv4 address |
| 564 |
# - interface GigabitEthernet0/0/0/3 |
| 565 |
# - no ipv4 address |
| 566 |
# - interface GigabitEthernet0/0/0/3.700 |
| 567 |
# - no ipv4 address |
| 568 |
# - interface GigabitEthernet0/0/0/4 |
| 569 |
# - no ipv6 address |
| 570 |
# after: |
| 571 |
# - name: Loopback888 |
| 572 |
# - name: Loopback999 |
| 573 |
# - name: GigabitEthernet0/0/0/1 |
| 574 |
# - name: GigabitEthernet0/0/0/2 |
| 575 |
# - name: GigabitEthernet0/0/0/3 |
| 576 |
# - name: GigabitEthernet0/0/0/3.700 |
| 577 |
# - name: GigabitEthernet0/0/0/4 |
| 578 |
|
| 579 |
# After state: |
| 580 |
# ------------- |
| 581 |
# |
| 582 |
# viosxr#show running-config interface |
| 583 |
# interface Loopback888 |
| 584 |
# ! |
| 585 |
# interface Loopback999 |
| 586 |
# ! |
| 587 |
# interface MgmtEth0/RP0/CPU0/0 |
| 588 |
# ipv4 address dhcp |
| 589 |
# ! |
| 590 |
# interface preconfigure GigabitEthernet0/0/0/1 |
| 591 |
# shutdown |
| 592 |
# ! |
| 593 |
# interface preconfigure GigabitEthernet0/0/0/2 |
| 594 |
# shutdown |
| 595 |
# ! |
| 596 |
# interface preconfigure GigabitEthernet0/0/0/3 |
| 597 |
# shutdown |
| 598 |
# ! |
| 599 |
# interface preconfigure GigabitEthernet0/0/0/3.700 |
| 600 |
# ! |
| 601 |
# interface preconfigure GigabitEthernet0/0/0/4 |
| 602 |
# shutdown |
| 603 |
# ! |
| 604 |
|
| 605 |
|
| 606 |
# Using parsed |
| 607 |
|
| 608 |
# File: parsed.cfg |
| 609 |
# ---------------- |
| 610 |
# |
| 611 |
# interface Loopback888 |
| 612 |
# description test for ansible |
| 613 |
# shutdown |
| 614 |
# ! |
| 615 |
# interface MgmtEth0/0/CPU0/0 |
| 616 |
# ipv4 address 10.8.38.70 255.255.255.0 |
| 617 |
# ! |
| 618 |
# interface GigabitEthernet0/0/0/0 |
| 619 |
# description Configured and Merged by Ansible-Network |
| 620 |
# mtu 66 |
| 621 |
# ipv4 address 192.0.2.1 255.255.255.0 |
| 622 |
# ipv4 address 192.0.2.2 255.255.255.0 secondary |
| 623 |
# ipv6 address 2001:db8:0:3::/64 |
| 624 |
# duplex half |
| 625 |
# ! |
| 626 |
# interface GigabitEthernet0/0/0/1 |
| 627 |
# description Configured and Merged by Ansible-Network |
| 628 |
# mtu 66 |
| 629 |
# speed 100 |
| 630 |
# duplex full |
| 631 |
# dot1q native vlan 10 |
| 632 |
# l2transport |
| 633 |
# l2protocol cdp forward |
| 634 |
# l2protocol pvst tunnel |
| 635 |
# propagate remote-status |
| 636 |
# ! |
| 637 |
# ! |
| 638 |
# interface GigabitEthernet0/0/0/3 |
| 639 |
# ipv4 address 192.0.22.1 255.255.255.0 |
| 640 |
# ipv4 address 192.0.23.1 255.255.255.0 |
| 641 |
# ! |
| 642 |
|
| 643 |
- name: Convert L3 interfaces config to argspec without connecting to the appliance |
| 644 |
cisco.iosxr.iosxr_l3_interfaces: |
| 645 |
running_config: "{{ lookup('file', './parsed.cfg') }}" |
| 646 |
state: parsed |
| 647 |
|
| 648 |
# Task Output |
| 649 |
# ----------- |
| 650 |
# |
| 651 |
# parsed: |
| 652 |
# - ipv4: |
| 653 |
# - address: 192.0.2.1 255.255.255.0 |
| 654 |
# - address: 192.0.2.2 255.255.255.0 |
| 655 |
# secondary: true |
| 656 |
# ipv6: |
| 657 |
# - address: 2001:db8:0:3::/64 |
| 658 |
# name: GigabitEthernet0/0/0/0 |
| 659 |
# - name: GigabitEthernet0/0/0/1 |
| 660 |
# - ipv4: |
| 661 |
# - address: 192.0.22.1 255.255.255.0 |
| 662 |
# - address: 192.0.23.1 255.255.255.0 |
| 663 |
# name: GigabitEthernet0/0/0/3 |
| 664 |
|
| 665 |
# Using rendered |
| 666 |
|
| 667 |
- name: Render platform specific commands from task input using rendered state |
| 668 |
cisco.iosxr.iosxr_l3_interfaces: |
| 669 |
config: |
| 670 |
- name: GigabitEthernet0/0/0/0 |
| 671 |
ipv4: |
| 672 |
- address: 198.51.100.1/24 |
| 673 |
- name: GigabitEthernet0/0/0/1 |
| 674 |
ipv6: |
| 675 |
- address: '2001:db8:0:3::/64' |
| 676 |
ipv4: |
| 677 |
- address: 192.0.2.1/24 |
| 678 |
- address: 192.0.2.2/24 |
| 679 |
secondary: true |
| 680 |
state: rendered |
| 681 |
|
| 682 |
|
| 683 |
# Task Output |
| 684 |
# ----------- |
| 685 |
# |
| 686 |
# rendered: |
| 687 |
# - interface GigabitEthernet0/0/0/0 |
| 688 |
# - ipv4 address 198.51.100.1 255.255.255.0 |
| 689 |
# - interface GigabitEthernet0/0/0/1 |
| 690 |
# - ipv4 address 192.0.2.2 255.255.255.0 secondary |
| 691 |
# - ipv4 address 192.0.2.1 255.255.255.0 |
| 692 |
# - ipv6 address 2001:db8:0:3::/64 |
| 693 |
|
| 694 |
# Using gathered |
| 695 |
|
| 696 |
# Before state: |
| 697 |
# ------------ |
| 698 |
# |
| 699 |
# RP/0/0/CPU0:an-iosxr-02#show running-config interface |
| 700 |
# interface Loopback888 |
| 701 |
# description test for ansible |
| 702 |
# shutdown |
| 703 |
# ! |
| 704 |
# interface MgmtEth0/0/CPU0/0 |
| 705 |
# ipv4 address 10.8.38.70 255.255.255.0 |
| 706 |
# ! |
| 707 |
# interface GigabitEthernet0/0/0/0 |
| 708 |
# description Configured and Merged by Ansible-Network |
| 709 |
# mtu 66 |
| 710 |
# ipv4 address 192.0.2.1 255.255.255.0 |
| 711 |
# ipv4 address 192.0.2.2 255.255.255.0 secondary |
| 712 |
# ipv6 address 2001:db8:0:3::/64 |
| 713 |
# duplex half |
| 714 |
# ! |
| 715 |
# interface GigabitEthernet0/0/0/1 |
| 716 |
# description Configured and Merged by Ansible-Network |
| 717 |
# mtu 66 |
| 718 |
# speed 100 |
| 719 |
# duplex full |
| 720 |
# dot1q native vlan 10 |
| 721 |
# l2transport |
| 722 |
# l2protocol cdp forward |
| 723 |
# l2protocol pvst tunnel |
| 724 |
# propagate remote-status |
| 725 |
# ! |
| 726 |
# ! |
| 727 |
# interface GigabitEthernet0/0/0/3 |
| 728 |
# shutdown |
| 729 |
# ! |
| 730 |
# interface GigabitEthernet0/0/0/4 |
| 731 |
# shutdown |
| 732 |
# dot1q native vlan 40 |
| 733 |
# ! |
| 734 |
|
| 735 |
- name: Gather l3 interfaces facts |
| 736 |
cisco.iosxr.iosxr_l3_interfaces: |
| 737 |
config: |
| 738 |
state: gathered |
| 739 |
|
| 740 |
# Task Output |
| 741 |
# ----------- |
| 742 |
# |
| 743 |
# gathered: |
| 744 |
# - name: Loopback888 |
| 745 |
# - ipv4: |
| 746 |
# - address: 192.0.2.1 255.255.255.0 |
| 747 |
# - address: 192.0.2.2 255.255.255.0 |
| 748 |
# secondary: true |
| 749 |
# ipv6: |
| 750 |
# - address: 2001:db8:0:3::/64 |
| 751 |
# name: GigabitEthernet0/0/0/0 |
| 752 |
# - name: GigabitEthernet0/0/0/1 |
| 753 |
# - name: GigabitEthernet0/0/0/3 |
| 754 |
# - name: GigabitEthernet0/0/0/4 |
| 755 |
|
| 756 |
# Using bidirectional flow monitoring (merged) |
| 757 |
|
| 758 |
# Before state: |
| 759 |
# ------------- |
| 760 |
# |
| 761 |
# viosxr#show running-config interface |
| 762 |
# interface GigabitEthernet0/0/0/0 |
| 763 |
# ipv4 address 198.51.100.1 255.255.255.0 |
| 764 |
# ! |
| 765 |
|
| 766 |
- name: Configure bidirectional NetFlow on an interface (merged) |
| 767 |
cisco.iosxr.iosxr_l3_interfaces: |
| 768 |
config: |
| 769 |
- name: GigabitEthernet0/0/0/0 |
| 770 |
flow: |
| 771 |
ipv4: |
| 772 |
monitor: FlowMap-IPv4 |
| 773 |
sampler: NETFLOW_1 |
| 774 |
direction: bidirectional |
| 775 |
ipv6: |
| 776 |
monitor: FlowMap-IPv6 |
| 777 |
sampler: NETFLOW_1 |
| 778 |
direction: bidirectional |
| 779 |
state: merged |
| 780 |
|
| 781 |
# Task Output |
| 782 |
# ----------- |
| 783 |
# |
| 784 |
# before: |
| 785 |
# - name: GigabitEthernet0/0/0/0 |
| 786 |
# ipv4: |
| 787 |
# - address: 198.51.100.1/24 |
| 788 |
# commands: |
| 789 |
# - interface GigabitEthernet0/0/0/0 |
| 790 |
# - flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 ingress |
| 791 |
# - flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 egress |
| 792 |
# - flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 ingress |
| 793 |
# - flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 egress |
| 794 |
# after: |
| 795 |
# - name: GigabitEthernet0/0/0/0 |
| 796 |
# ipv4: |
| 797 |
# - address: 198.51.100.1/24 |
| 798 |
# flow: |
| 799 |
# ipv4: |
| 800 |
# monitor: FlowMap-IPv4 |
| 801 |
# sampler: NETFLOW_1 |
| 802 |
# direction: bidirectional |
| 803 |
# ipv6: |
| 804 |
# monitor: FlowMap-IPv6 |
| 805 |
# sampler: NETFLOW_1 |
| 806 |
# direction: bidirectional |
| 807 |
|
| 808 |
# After state: |
| 809 |
# ------------ |
| 810 |
# |
| 811 |
# viosxr#show running-config interface |
| 812 |
# interface GigabitEthernet0/0/0/0 |
| 813 |
# ipv4 address 198.51.100.1 255.255.255.0 |
| 814 |
# flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 ingress |
| 815 |
# flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 egress |
| 816 |
# flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 ingress |
| 817 |
# flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 egress |
| 818 |
# ! |
| 819 |
|
| 820 |
# Using bidirectional flow monitoring (deleted) |
| 821 |
|
| 822 |
# Before state: |
| 823 |
# ------------- |
| 824 |
# |
| 825 |
# viosxr#show running-config interface |
| 826 |
# interface GigabitEthernet0/0/0/0 |
| 827 |
# ipv4 address 198.51.100.1 255.255.255.0 |
| 828 |
# flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 ingress |
| 829 |
# flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 egress |
| 830 |
# flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 ingress |
| 831 |
# flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 egress |
| 832 |
# ! |
| 833 |
|
| 834 |
- name: >- |
| 835 |
Remove L3 attributes for an interface including bidirectional flow |
| 836 |
(does not remove the interface itself) |
| 837 |
cisco.iosxr.iosxr_l3_interfaces: |
| 838 |
config: |
| 839 |
- name: GigabitEthernet0/0/0/0 |
| 840 |
state: deleted |
| 841 |
|
| 842 |
# Task Output |
| 843 |
# ----------- |
| 844 |
# |
| 845 |
# before: |
| 846 |
# - name: GigabitEthernet0/0/0/0 |
| 847 |
# ipv4: |
| 848 |
# - address: 198.51.100.1/24 |
| 849 |
# flow: |
| 850 |
# ipv4: |
| 851 |
# monitor: FlowMap-IPv4 |
| 852 |
# sampler: NETFLOW_1 |
| 853 |
# direction: bidirectional |
| 854 |
# ipv6: |
| 855 |
# monitor: FlowMap-IPv6 |
| 856 |
# sampler: NETFLOW_1 |
| 857 |
# direction: bidirectional |
| 858 |
# commands: |
| 859 |
# - interface GigabitEthernet0/0/0/0 |
| 860 |
# - no ipv4 address |
| 861 |
# - no flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 ingress |
| 862 |
# - no flow ipv4 monitor FlowMap-IPv4 sampler NETFLOW_1 egress |
| 863 |
# - no flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 ingress |
| 864 |
# - no flow ipv6 monitor FlowMap-IPv6 sampler NETFLOW_1 egress |
| 865 |
# after: |
| 866 |
# - name: GigabitEthernet0/0/0/0 |
| 867 |
|
| 868 |
# After state: |
| 869 |
# ------------ |
| 870 |
# |
| 871 |
# viosxr#show running-config interface |
| 872 |
# interface GigabitEthernet0/0/0/0 |
| 873 |
# ! |
| 874 |
""" |
| 875 |
|
| 876 |
RETURN = """ |
| 877 |
before: |
| 878 |
description: The configuration as structured data prior to module invocation. |
| 879 |
returned: always |
| 880 |
type: list |
| 881 |
sample: The configuration returned will always be in the same format of the parameters above. |
| 882 |
after: |
| 883 |
description: The configuration as structured data after module completion. |
| 884 |
returned: when changed |
| 885 |
type: list |
| 886 |
sample: The configuration returned will always be in the same format of the parameters above. |
| 887 |
commands: |
| 888 |
description: The set of commands pushed to the remote device |
| 889 |
returned: always |
| 890 |
type: list |
| 891 |
sample: ['interface GigabitEthernet0/0/0/1', 'ipv4 address 192.168.0.1 255.255.255.0'] |
| 892 |
""" |
| 893 |
|
| 894 |
|
| 895 |
from ansible.module_utils.basic import AnsibleModule |
| 896 |
|
| 897 |
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.l3_interfaces.l3_interfaces import ( |
| 898 |
L3_InterfacesArgs, |
| 899 |
) |
| 900 |
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.l3_interfaces.l3_interfaces import ( |
| 901 |
L3_Interfaces, |
| 902 |
) |
| 903 |
|
| 904 |
|
| 905 |
def main(): |
| 906 |
""" |
| 907 |
Main entry point for module execution |
| 908 |
:returns: the result form module invocation |
| 909 |
""" |
| 910 |
required_if = [ |
| 911 |
("state", "merged", ("config",)), |
| 912 |
("state", "replaced", ("config",)), |
| 913 |
("state", "rendered", ("config",)), |
| 914 |
("state", "overridden", ("config",)), |
| 915 |
("state", "parsed", ("running_config",)), |
| 916 |
] |
| 917 |
|
| 918 |
mutually_exclusive = [("config", "running_config")] |
| 919 |
module = AnsibleModule( |
| 920 |
argument_spec=L3_InterfacesArgs.argument_spec, |
| 921 |
required_if=required_if, |
| 922 |
supports_check_mode=True, |
| 923 |
mutually_exclusive=mutually_exclusive, |
| 924 |
) |
| 925 |
|
| 926 |
result = L3_Interfaces(module).execute_module() |
| 927 |
module.exit_json(**result) |
| 928 |
|
| 929 |
|
| 930 |
if __name__ == "__main__": |
| 931 |
main() |