| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright 2025 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_bfd_interfaces |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
|
| 13 |
|
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = """ |
| 17 |
module: ios_bfd_interfaces |
| 18 |
short_description: Resource module to configure bfd in interfaces. |
| 19 |
description: This module manages the bfd configuration in interface of Cisco IOS network devices. |
| 20 |
version_added: 11.3.0 |
| 21 |
author: |
| 22 |
- Sagar Paul (@KB-perByte) |
| 23 |
notes: |
| 24 |
- Tested against Cisco IOSXE Version 17.3 on CML. |
| 25 |
- This module works with connection C(network_cli). |
| 26 |
See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html) |
| 27 |
- The module examples uses callback plugin (stdout_callback = yaml) to generate task |
| 28 |
output in yaml format. |
| 29 |
options: |
| 30 |
config: |
| 31 |
description: A list of interface options, to configure bfd. |
| 32 |
type: list |
| 33 |
elements: dict |
| 34 |
suboptions: |
| 35 |
name: |
| 36 |
description: |
| 37 |
- Full name of interface, e.g. GigabitEthernet0/2, loopback999. |
| 38 |
- Short interface names like Gi0/2, Lo999 may impact idempotency. |
| 39 |
type: str |
| 40 |
required: true |
| 41 |
echo: |
| 42 |
description: |
| 43 |
- Use echo adjunct as bfd detection mechanism. |
| 44 |
type: bool |
| 45 |
bfd: |
| 46 |
description: |
| 47 |
- Enable or disable bfd for the interface. |
| 48 |
- Default value for appliance might impact idempotency. |
| 49 |
type: bool |
| 50 |
template: |
| 51 |
description: |
| 52 |
- BFD template (might impact other BFD configuration), |
| 53 |
- Ansible won't guarantee state operations. |
| 54 |
type: str |
| 55 |
local_address: |
| 56 |
description: |
| 57 |
- BFD local address. |
| 58 |
type: str |
| 59 |
jitter: |
| 60 |
description: |
| 61 |
- Enable BFD interval transmit jittering. |
| 62 |
type: bool |
| 63 |
interval: |
| 64 |
description: |
| 65 |
- Transmit interval between BFD packets |
| 66 |
type: dict |
| 67 |
suboptions: |
| 68 |
input: |
| 69 |
description: |
| 70 |
- Interval between transmitted BFD control packets 50 - 9999 Milliseconds |
| 71 |
type: int |
| 72 |
min_rx: |
| 73 |
description: |
| 74 |
- Minimum receive interval capability 50 - 9999 Milliseconds |
| 75 |
type: int |
| 76 |
multiplier: |
| 77 |
description: |
| 78 |
- Detection multiplier 3 - 50 |
| 79 |
type: int |
| 80 |
running_config: |
| 81 |
description: |
| 82 |
- This option is used only with state I(parsed). |
| 83 |
- The value of this option should be the output received from the IOS XE device by |
| 84 |
executing the command B(show running-config | section ^interface). |
| 85 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 86 |
transforms it into Ansible structured data as per the resource module's argspec |
| 87 |
and the value is then returned in the I(parsed) key within the result. |
| 88 |
type: str |
| 89 |
state: |
| 90 |
choices: |
| 91 |
- merged |
| 92 |
- replaced |
| 93 |
- overridden |
| 94 |
- deleted |
| 95 |
- rendered |
| 96 |
- gathered |
| 97 |
- parsed |
| 98 |
default: merged |
| 99 |
description: |
| 100 |
- The state the configuration should be left in |
| 101 |
- The states I(rendered), I(gathered) and I(parsed) does not perform any change |
| 102 |
on the device. |
| 103 |
- The state I(rendered) will transform the configuration in C(config) option to |
| 104 |
platform specific CLI commands which will be returned in the I(rendered) key |
| 105 |
within the result. For state I(rendered) active connection to remote host is |
| 106 |
not required. |
| 107 |
- The state I(gathered) will fetch the running configuration from device and transform |
| 108 |
it into structured data in the format as per the resource module argspec and |
| 109 |
the value is returned in the I(gathered) key within the result. |
| 110 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 111 |
transforms it into JSON format as per the resource module parameters and the |
| 112 |
value is returned in the I(parsed) key within the result. The value of C(running_config) |
| 113 |
option should be the same format as the output of command I(show running-config |
| 114 |
| section interface) executed on device. For state I(parsed) active |
| 115 |
connection to remote host is not required. |
| 116 |
type: str |
| 117 |
""" |
| 118 |
|
| 119 |
EXAMPLES = """ |
| 120 |
# Using state: merged |
| 121 |
|
| 122 |
# Before state: |
| 123 |
# ------------- |
| 124 |
|
| 125 |
# router-ios#show running-config | section ^interface |
| 126 |
# interface GigabitEthernet1 |
| 127 |
# ip address dhcp |
| 128 |
# negotiation auto |
| 129 |
# interface GigabitEthernet2 |
| 130 |
# no ip address |
| 131 |
# shutdown |
| 132 |
# negotiation auto |
| 133 |
# interface GigabitEthernet3 |
| 134 |
# no ip address |
| 135 |
# shutdown |
| 136 |
# negotiation auto |
| 137 |
# interface GigabitEthernet4 |
| 138 |
# no ip address |
| 139 |
# shutdown |
| 140 |
# negotiation auto |
| 141 |
|
| 142 |
|
| 143 |
- name: Apply the provided BFD configuration to interfaces |
| 144 |
cisco.ios.ios_bfd_interfaces: |
| 145 |
config: |
| 146 |
- name: GigabitEthernet1 |
| 147 |
bfd: true |
| 148 |
jitter: false |
| 149 |
interval: |
| 150 |
input: 100 |
| 151 |
min_rx: 100 |
| 152 |
multiplier: 3 |
| 153 |
local_address: 10.0.1.2 |
| 154 |
template: ANSIBLE |
| 155 |
- name: GigabitEthernet2 |
| 156 |
bfd: true |
| 157 |
jitter: true |
| 158 |
interval: |
| 159 |
input: 100 |
| 160 |
min_rx: 100 |
| 161 |
multiplier: 3 |
| 162 |
- name: GigabitEthernet4 |
| 163 |
template: ANSIBLE_Tempalte |
| 164 |
state: merged |
| 165 |
|
| 166 |
# Commands Fired: |
| 167 |
# --------------- |
| 168 |
|
| 169 |
# after: |
| 170 |
# - interval: |
| 171 |
# input: 100 |
| 172 |
# min_rx: 100 |
| 173 |
# multiplier: 3 |
| 174 |
# jitter: false |
| 175 |
# local_address: 10.0.1.2 |
| 176 |
# name: GigabitEthernet1 |
| 177 |
# - interval: |
| 178 |
# input: 100 |
| 179 |
# min_rx: 100 |
| 180 |
# multiplier: 3 |
| 181 |
# name: GigabitEthernet2 |
| 182 |
# - name: GigabitEthernet3 |
| 183 |
# - name: GigabitEthernet4 |
| 184 |
# template: ANSIBLE_Tempalte |
| 185 |
# before: |
| 186 |
# - name: GigabitEthernet1 |
| 187 |
# - name: GigabitEthernet2 |
| 188 |
# - name: GigabitEthernet3 |
| 189 |
# - name: GigabitEthernet4 |
| 190 |
# changed: true |
| 191 |
# commands: |
| 192 |
# - interface GigabitEthernet1 |
| 193 |
# - bfd enable |
| 194 |
# - bfd local-address 10.0.1.2 |
| 195 |
# - bfd interval 100 min_rx 100 multiplier 3 |
| 196 |
# - bfd template ANSIBLE |
| 197 |
# - no bfd jitter |
| 198 |
# - interface GigabitEthernet2 |
| 199 |
# - bfd enable |
| 200 |
# - bfd jitter |
| 201 |
# - bfd interval 100 min_rx 100 multiplier 3 |
| 202 |
# - interface GigabitEthernet4 |
| 203 |
# - bfd template ANSIBLE_Tempalte |
| 204 |
|
| 205 |
# After state: |
| 206 |
# ------------ |
| 207 |
|
| 208 |
# router-ios#show running-config | section ^interface |
| 209 |
# interface GigabitEthernet1 |
| 210 |
# ip address dhcp |
| 211 |
# negotiation auto |
| 212 |
# bfd local-address 10.0.1.2 |
| 213 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 214 |
# no bfd jitter |
| 215 |
# interface GigabitEthernet2 |
| 216 |
# no ip address |
| 217 |
# shutdown |
| 218 |
# negotiation auto |
| 219 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 220 |
# interface GigabitEthernet3 |
| 221 |
# no ip address |
| 222 |
# shutdown |
| 223 |
# negotiation auto |
| 224 |
# interface GigabitEthernet4 |
| 225 |
# no ip address |
| 226 |
# shutdown |
| 227 |
# negotiation auto |
| 228 |
# bfd template ANSIBLE_Tempalte |
| 229 |
|
| 230 |
# Using state: replaced |
| 231 |
|
| 232 |
# Before state: |
| 233 |
# ------------- |
| 234 |
|
| 235 |
# router-ios#show running-config | section ^interface |
| 236 |
# interface GigabitEthernet1 |
| 237 |
# ip address dhcp |
| 238 |
# negotiation auto |
| 239 |
# bfd local-address 10.0.1.2 |
| 240 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 241 |
# no bfd jitter |
| 242 |
# interface GigabitEthernet2 |
| 243 |
# no ip address |
| 244 |
# shutdown |
| 245 |
# negotiation auto |
| 246 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 247 |
# interface GigabitEthernet3 |
| 248 |
# no ip address |
| 249 |
# shutdown |
| 250 |
# negotiation auto |
| 251 |
# interface GigabitEthernet4 |
| 252 |
# no ip address |
| 253 |
# shutdown |
| 254 |
# negotiation auto |
| 255 |
# bfd template ANSIBLE_Tempalte |
| 256 |
|
| 257 |
|
| 258 |
- name: Replace BFD configuration for specified interfaces |
| 259 |
cisco.ios.ios_bfd_interfaces: |
| 260 |
config: |
| 261 |
- name: GigabitEthernet1 |
| 262 |
bfd: true |
| 263 |
echo: true |
| 264 |
jitter: true |
| 265 |
interval: |
| 266 |
input: 100 |
| 267 |
min_rx: 100 |
| 268 |
multiplier: 3 |
| 269 |
local_address: 10.0.1.2 |
| 270 |
template: ANSIBLE |
| 271 |
- name: GigabitEthernet2 |
| 272 |
bfd: true |
| 273 |
echo: true |
| 274 |
jitter: true |
| 275 |
interval: |
| 276 |
input: 100 |
| 277 |
min_rx: 100 |
| 278 |
multiplier: 3 |
| 279 |
- name: GigabitEthernet6 |
| 280 |
template: ANSIBLE_3Tempalte |
| 281 |
state: replaced |
| 282 |
|
| 283 |
# Commands Fired: |
| 284 |
# --------------- |
| 285 |
|
| 286 |
# "commands": [ |
| 287 |
# "interface GigabitEthernet1", |
| 288 |
# "bfd enable", |
| 289 |
# "bfd echo", |
| 290 |
# "bfd jitter", |
| 291 |
# "bfd local-address 10.0.1.2", |
| 292 |
# "bfd interval 100 min_rx 100 multiplier 3", |
| 293 |
# "bfd template ANSIBLE", |
| 294 |
# "interface GigabitEthernet2", |
| 295 |
# "bfd enable", |
| 296 |
# "bfd echo", |
| 297 |
# "bfd jitter", |
| 298 |
# "bfd interval 100 min_rx 100 multiplier 3", |
| 299 |
# "no bfd template OLD_TEMPLATE", |
| 300 |
# "interface GigabitEthernet6", |
| 301 |
# "bfd template ANSIBLE_3Tempalte" |
| 302 |
# ] |
| 303 |
|
| 304 |
# After state: |
| 305 |
# ------------ |
| 306 |
|
| 307 |
# router-ios#show running-config | section ^interface |
| 308 |
# interface GigabitEthernet1 |
| 309 |
# description Ansible UT interface 1 |
| 310 |
# no shutdown |
| 311 |
# bfd enable |
| 312 |
# bfd echo |
| 313 |
# bfd jitter |
| 314 |
# bfd local-address 10.0.1.2 |
| 315 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 316 |
# bfd template ANSIBLE |
| 317 |
# interface GigabitEthernet2 |
| 318 |
# description Ansible UT interface 2 |
| 319 |
# ip address dhcp |
| 320 |
# bfd enable |
| 321 |
# bfd echo |
| 322 |
# bfd jitter |
| 323 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 324 |
# interface GigabitEthernet3 |
| 325 |
# description Ansible UT interface 3 |
| 326 |
# no ip address |
| 327 |
# shutdown |
| 328 |
# bfd jitter |
| 329 |
# bfd local-address 10.0.1.2 |
| 330 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 331 |
# interface GigabitEthernet6 |
| 332 |
# bfd template ANSIBLE_3Tempalte |
| 333 |
|
| 334 |
# Using state: overridden |
| 335 |
|
| 336 |
# Before state: |
| 337 |
# ------------- |
| 338 |
|
| 339 |
# router-ios#show running-config | section ^interface |
| 340 |
# interface GigabitEthernet1 |
| 341 |
# description Ansible UT interface 1 |
| 342 |
# no shutdown |
| 343 |
# bfd local-address 10.0.0.1 |
| 344 |
# bfd interval 57 min_rx 66 multiplier 45 |
| 345 |
# interface GigabitEthernet2 |
| 346 |
# description Ansible UT interface 2 |
| 347 |
# ip address dhcp |
| 348 |
# bfd template OLD_TEMPLATE |
| 349 |
# interface GigabitEthernet3 |
| 350 |
# description Ansible UT interface 3 |
| 351 |
# no ip address |
| 352 |
# shutdown |
| 353 |
# bfd jitter |
| 354 |
# bfd local-address 10.0.1.2 |
| 355 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 356 |
|
| 357 |
- name: Override all BFD configuration with provided configuration |
| 358 |
cisco.ios.ios_bfd_interfaces: |
| 359 |
config: |
| 360 |
- name: GigabitEthernet1 |
| 361 |
bfd: true |
| 362 |
echo: true |
| 363 |
jitter: true |
| 364 |
interval: |
| 365 |
input: 100 |
| 366 |
min_rx: 100 |
| 367 |
multiplier: 3 |
| 368 |
local_address: 10.0.1.2 |
| 369 |
template: ANSIBLE |
| 370 |
- name: GigabitEthernet2 |
| 371 |
bfd: true |
| 372 |
echo: true |
| 373 |
jitter: true |
| 374 |
interval: |
| 375 |
input: 100 |
| 376 |
min_rx: 100 |
| 377 |
multiplier: 3 |
| 378 |
- name: GigabitEthernet6 |
| 379 |
template: ANSIBLE_3Tempalte |
| 380 |
state: overridden |
| 381 |
|
| 382 |
# Commands Fired: |
| 383 |
# --------------- |
| 384 |
|
| 385 |
# "commands": [ |
| 386 |
# "interface GigabitEthernet3", |
| 387 |
# "no bfd jitter", |
| 388 |
# "no bfd local-address 10.0.1.2", |
| 389 |
# "no bfd interval 50 min_rx 50 multiplier 3", |
| 390 |
# "interface GigabitEthernet1", |
| 391 |
# "bfd enable", |
| 392 |
# "bfd echo", |
| 393 |
# "bfd jitter", |
| 394 |
# "bfd local-address 10.0.1.2", |
| 395 |
# "bfd interval 100 min_rx 100 multiplier 3", |
| 396 |
# "bfd template ANSIBLE", |
| 397 |
# "interface GigabitEthernet2", |
| 398 |
# "bfd enable", |
| 399 |
# "bfd echo", |
| 400 |
# "bfd jitter", |
| 401 |
# "bfd interval 100 min_rx 100 multiplier 3", |
| 402 |
# "no bfd template OLD_TEMPLATE", |
| 403 |
# "interface GigabitEthernet6", |
| 404 |
# "bfd template ANSIBLE_3Tempalte" |
| 405 |
# ] |
| 406 |
|
| 407 |
# After state: |
| 408 |
# ------------ |
| 409 |
|
| 410 |
# router-ios#show running-config | section ^interface |
| 411 |
# interface GigabitEthernet1 |
| 412 |
# description Ansible UT interface 1 |
| 413 |
# no shutdown |
| 414 |
# bfd enable |
| 415 |
# bfd echo |
| 416 |
# bfd jitter |
| 417 |
# bfd local-address 10.0.1.2 |
| 418 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 419 |
# bfd template ANSIBLE |
| 420 |
# interface GigabitEthernet2 |
| 421 |
# description Ansible UT interface 2 |
| 422 |
# ip address dhcp |
| 423 |
# bfd enable |
| 424 |
# bfd echo |
| 425 |
# bfd jitter |
| 426 |
# bfd interval 100 min_rx 100 multiplier 3 |
| 427 |
# interface GigabitEthernet3 |
| 428 |
# description Ansible UT interface 3 |
| 429 |
# no ip address |
| 430 |
# shutdown |
| 431 |
# interface GigabitEthernet6 |
| 432 |
# bfd template ANSIBLE_3Tempalte |
| 433 |
|
| 434 |
# Using state: deleted |
| 435 |
|
| 436 |
# Before state: |
| 437 |
# ------------- |
| 438 |
|
| 439 |
# router-ios#show running-config | section ^interface |
| 440 |
# interface GigabitEthernet1 |
| 441 |
# description Ansible UT interface 1 |
| 442 |
# no shutdown |
| 443 |
# bfd local-address 10.0.0.1 |
| 444 |
# bfd interval 57 min_rx 66 multiplier 45 |
| 445 |
# interface GigabitEthernet2 |
| 446 |
# description Ansible UT interface 2 |
| 447 |
# ip address dhcp |
| 448 |
# bfd template OLD_TEMPLATE |
| 449 |
# interface GigabitEthernet3 |
| 450 |
# description Ansible UT interface 3 |
| 451 |
# no ip address |
| 452 |
# shutdown |
| 453 |
# bfd jitter |
| 454 |
# bfd local-address 10.0.1.2 |
| 455 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 456 |
|
| 457 |
- name: Delete BFD configuration for specified interfaces |
| 458 |
cisco.ios.ios_bfd_interfaces: |
| 459 |
config: |
| 460 |
- name: GigabitEthernet1 |
| 461 |
- name: GigabitEthernet2 |
| 462 |
state: deleted |
| 463 |
|
| 464 |
# Commands Fired: |
| 465 |
# --------------- |
| 466 |
|
| 467 |
# "commands": [ |
| 468 |
# "interface GigabitEthernet1", |
| 469 |
# "no bfd local-address 10.0.0.1", |
| 470 |
# "no bfd interval 57 min_rx 66 multiplier 45", |
| 471 |
# "interface GigabitEthernet2", |
| 472 |
# "no bfd template OLD_TEMPLATE" |
| 473 |
# ] |
| 474 |
|
| 475 |
# After state: |
| 476 |
# ------------ |
| 477 |
|
| 478 |
# router-ios#show running-config | section ^interface |
| 479 |
# interface GigabitEthernet1 |
| 480 |
# description Ansible UT interface 1 |
| 481 |
# no shutdown |
| 482 |
# interface GigabitEthernet2 |
| 483 |
# description Ansible UT interface 2 |
| 484 |
# ip address dhcp |
| 485 |
# interface GigabitEthernet3 |
| 486 |
# description Ansible UT interface 3 |
| 487 |
# no ip address |
| 488 |
# shutdown |
| 489 |
# bfd jitter |
| 490 |
# bfd local-address 10.0.1.2 |
| 491 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 492 |
|
| 493 |
# Using state: gathered |
| 494 |
|
| 495 |
# Before state: |
| 496 |
# ------------- |
| 497 |
|
| 498 |
# router-ios#show running-config | section ^interface |
| 499 |
# interface GigabitEthernet1 |
| 500 |
# description Ansible UT interface 1 |
| 501 |
# no shutdown |
| 502 |
# bfd local-address 10.0.0.1 |
| 503 |
# bfd interval 57 min_rx 66 multiplier 45 |
| 504 |
# interface GigabitEthernet2 |
| 505 |
# description Ansible UT interface 2 |
| 506 |
# ip address dhcp |
| 507 |
# bfd template OLD_TEMPLATE |
| 508 |
# interface GigabitEthernet3 |
| 509 |
# description Ansible UT interface 3 |
| 510 |
# no ip address |
| 511 |
# shutdown |
| 512 |
# bfd jitter |
| 513 |
# bfd local-address 10.0.1.2 |
| 514 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 515 |
|
| 516 |
- name: Gather listed BFD interfaces config |
| 517 |
cisco.ios.ios_bfd_interfaces: |
| 518 |
state: gathered |
| 519 |
|
| 520 |
# Module Execution Result: |
| 521 |
# ------------------------ |
| 522 |
|
| 523 |
# "gathered": [ |
| 524 |
# { |
| 525 |
# "name": "GigabitEthernet1", |
| 526 |
# "local_address": "10.0.0.1", |
| 527 |
# "interval": { |
| 528 |
# "input": 57, |
| 529 |
# "min_rx": 66, |
| 530 |
# "multiplier": 45 |
| 531 |
# } |
| 532 |
# }, |
| 533 |
# { |
| 534 |
# "name": "GigabitEthernet2", |
| 535 |
# "template": "OLD_TEMPLATE" |
| 536 |
# }, |
| 537 |
# { |
| 538 |
# "name": "GigabitEthernet3", |
| 539 |
# "jitter": true, |
| 540 |
# "local_address": "10.0.1.2", |
| 541 |
# "interval": { |
| 542 |
# "input": 50, |
| 543 |
# "min_rx": 50, |
| 544 |
# "multiplier": 3 |
| 545 |
# } |
| 546 |
# } |
| 547 |
# ] |
| 548 |
|
| 549 |
# After state: |
| 550 |
# ------------- |
| 551 |
|
| 552 |
# router-ios#show running-config | section ^interface |
| 553 |
# interface GigabitEthernet1 |
| 554 |
# description Ansible UT interface 1 |
| 555 |
# no shutdown |
| 556 |
# bfd local-address 10.0.0.1 |
| 557 |
# bfd interval 57 min_rx 66 multiplier 45 |
| 558 |
# interface GigabitEthernet2 |
| 559 |
# description Ansible UT interface 2 |
| 560 |
# ip address dhcp |
| 561 |
# bfd template OLD_TEMPLATE |
| 562 |
# interface GigabitEthernet3 |
| 563 |
# description Ansible UT interface 3 |
| 564 |
# no ip address |
| 565 |
# shutdown |
| 566 |
# bfd jitter |
| 567 |
# bfd local-address 10.0.1.2 |
| 568 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 569 |
|
| 570 |
# Using state: rendered |
| 571 |
|
| 572 |
- name: Render the commands for provided configuration |
| 573 |
cisco.ios.ios_bfd_interfaces: |
| 574 |
config: |
| 575 |
- name: GigabitEthernet1 |
| 576 |
local_address: 10.0.0.1 |
| 577 |
interval: |
| 578 |
input: 57 |
| 579 |
min_rx: 66 |
| 580 |
multiplier: 45 |
| 581 |
- name: GigabitEthernet2 |
| 582 |
template: OLD_TEMPLATE |
| 583 |
- name: GigabitEthernet3 |
| 584 |
jitter: true |
| 585 |
local_address: 10.0.1.2 |
| 586 |
interval: |
| 587 |
input: 50 |
| 588 |
min_rx: 50 |
| 589 |
multiplier: 3 |
| 590 |
state: rendered |
| 591 |
|
| 592 |
# Module Execution Result: |
| 593 |
# ------------------------ |
| 594 |
|
| 595 |
# "rendered": [ |
| 596 |
# "interface GigabitEthernet1", |
| 597 |
# "bfd local-address 10.0.0.1", |
| 598 |
# "bfd interval 57 min_rx 66 multiplier 45", |
| 599 |
# "interface GigabitEthernet2", |
| 600 |
# "bfd template OLD_TEMPLATE", |
| 601 |
# "interface GigabitEthernet3", |
| 602 |
# "bfd jitter", |
| 603 |
# "bfd local-address 10.0.1.2", |
| 604 |
# "bfd interval 50 min_rx 50 multiplier 3" |
| 605 |
# ] |
| 606 |
|
| 607 |
# Using state: parsed |
| 608 |
|
| 609 |
# File: parsed.cfg |
| 610 |
# ---------------- |
| 611 |
|
| 612 |
# interface GigabitEthernet1 |
| 613 |
# description Ansible UT interface 1 |
| 614 |
# no shutdown |
| 615 |
# bfd local-address 10.0.0.1 |
| 616 |
# bfd interval 57 min_rx 66 multiplier 45 |
| 617 |
# interface GigabitEthernet2 |
| 618 |
# description Ansible UT interface 2 |
| 619 |
# ip address dhcp |
| 620 |
# bfd template OLD_TEMPLATE |
| 621 |
# interface GigabitEthernet3 |
| 622 |
# description Ansible UT interface 3 |
| 623 |
# no ip address |
| 624 |
# shutdown |
| 625 |
# no bfd jitter |
| 626 |
# bfd local-address 10.0.1.2 |
| 627 |
# bfd interval 50 min_rx 50 multiplier 3 |
| 628 |
|
| 629 |
- name: Parse the provided configuration with the existing running configuration |
| 630 |
cisco.ios.ios_bfd_interfaces: |
| 631 |
running_config: "{{ lookup('file', 'parsed.cfg') }}" |
| 632 |
state: parsed |
| 633 |
|
| 634 |
# Module Execution Result: |
| 635 |
# ------------------------ |
| 636 |
|
| 637 |
# "parsed": [ |
| 638 |
# { |
| 639 |
# "name": "GigabitEthernet1", |
| 640 |
# "local_address": "10.0.0.1", |
| 641 |
# "interval": { |
| 642 |
# "input": 57, |
| 643 |
# "min_rx": 66, |
| 644 |
# "multiplier": 45 |
| 645 |
# } |
| 646 |
# }, |
| 647 |
# { |
| 648 |
# "name": "GigabitEthernet2", |
| 649 |
# "template": "OLD_TEMPLATE" |
| 650 |
# }, |
| 651 |
# { |
| 652 |
# "name": "GigabitEthernet3", |
| 653 |
# "jitter": false, |
| 654 |
# "local_address": "10.0.1.2", |
| 655 |
# "interval": { |
| 656 |
# "input": 50, |
| 657 |
# "min_rx": 50, |
| 658 |
# "multiplier": 3 |
| 659 |
# } |
| 660 |
# } |
| 661 |
# ] |
| 662 |
""" |
| 663 |
|
| 664 |
RETURN = """ |
| 665 |
before: |
| 666 |
description: The configuration prior to the module execution. |
| 667 |
returned: when I(state) is C(merged), C(replaced), C(overridden) or C(deleted) |
| 668 |
type: list |
| 669 |
sample: > |
| 670 |
This output will always be in the same format as the |
| 671 |
module argspec. |
| 672 |
after: |
| 673 |
description: The resulting configuration after module execution. |
| 674 |
returned: when changed |
| 675 |
type: list |
| 676 |
sample: > |
| 677 |
This output will always be in the same format as the |
| 678 |
module argspec. |
| 679 |
commands: |
| 680 |
description: The set of commands pushed to the remote device. |
| 681 |
returned: when I(state) is C(merged), C(replaced), C(overridden) or C(deleted) |
| 682 |
type: list |
| 683 |
sample: |
| 684 |
- interface GigabitEthernet0/2 |
| 685 |
- no bfd jitter |
| 686 |
- bfd interval 100 min_rx 100 multiplier 3 |
| 687 |
rendered: |
| 688 |
description: The provided configuration in the task rendered in device-native format (offline). |
| 689 |
returned: when I(state) is C(rendered) |
| 690 |
type: list |
| 691 |
sample: |
| 692 |
- interface GigabitEthernet0/2 |
| 693 |
- bfd echo |
| 694 |
- bfd jitter |
| 695 |
gathered: |
| 696 |
description: Facts about the network resource gathered from the remote device as structured data. |
| 697 |
returned: when I(state) is C(gathered) |
| 698 |
type: list |
| 699 |
sample: > |
| 700 |
This output will always be in the same format as the |
| 701 |
module argspec. |
| 702 |
parsed: |
| 703 |
description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. |
| 704 |
returned: when I(state) is C(parsed) |
| 705 |
type: list |
| 706 |
sample: > |
| 707 |
This output will always be in the same format as the |
| 708 |
module argspec. |
| 709 |
""" |
| 710 |
|
| 711 |
from ansible.module_utils.basic import AnsibleModule |
| 712 |
|
| 713 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.bfd_interfaces.bfd_interfaces import ( |
| 714 |
Bfd_interfacesArgs, |
| 715 |
) |
| 716 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.bfd_interfaces.bfd_interfaces import ( |
| 717 |
Bfd_interfaces, |
| 718 |
) |
| 719 |
|
| 720 |
|
| 721 |
def main(): |
| 722 |
""" |
| 723 |
Main entry point for module execution |
| 724 |
|
| 725 |
:returns: the result form module invocation |
| 726 |
""" |
| 727 |
module = AnsibleModule( |
| 728 |
argument_spec=Bfd_interfacesArgs.argument_spec, |
| 729 |
mutually_exclusive=[["config", "running_config"]], |
| 730 |
required_if=[ |
| 731 |
["state", "merged", ["config"]], |
| 732 |
["state", "replaced", ["config"]], |
| 733 |
["state", "overridden", ["config"]], |
| 734 |
["state", "rendered", ["config"]], |
| 735 |
["state", "parsed", ["running_config"]], |
| 736 |
], |
| 737 |
supports_check_mode=True, |
| 738 |
) |
| 739 |
|
| 740 |
result = Bfd_interfaces(module).execute_module() |
| 741 |
module.exit_json(**result) |
| 742 |
|
| 743 |
|
| 744 |
if __name__ == "__main__": |
| 745 |
main() |