| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright 2023 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_vxlan_vtep |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
|
| 13 |
|
| 14 |
__metaclass__ = type |
| 15 |
|
| 16 |
DOCUMENTATION = """ |
| 17 |
module: ios_vxlan_vtep |
| 18 |
short_description: Resource module to configure VXLAN VTEP interface. |
| 19 |
description: This module provides declarative management of VXLAN VTEP interface on Cisco IOS network |
| 20 |
devices. |
| 21 |
version_added: 5.3.0 |
| 22 |
author: Padmini Priyadarshini Sivaraj (@PadminiSivaraj) |
| 23 |
notes: |
| 24 |
- Tested against Cisco IOS-XE device with Version 17.13.01 on Cat9k 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 |
options: |
| 28 |
config: |
| 29 |
description: A dictionary of VXLAN VTEP interface option |
| 30 |
type: list |
| 31 |
elements: dict |
| 32 |
suboptions: |
| 33 |
interface: |
| 34 |
description: |
| 35 |
- VXLAN VTEP interface |
| 36 |
type: str |
| 37 |
required: true |
| 38 |
source_interface: |
| 39 |
description: |
| 40 |
- Source interface for the VXLAN VTEP interface |
| 41 |
type: str |
| 42 |
host_reachability_bgp: |
| 43 |
description: |
| 44 |
- Host reachability using EVPN protocol |
| 45 |
type: bool |
| 46 |
member: |
| 47 |
description: |
| 48 |
- Configure VNI member |
| 49 |
type: dict |
| 50 |
suboptions: |
| 51 |
vni: |
| 52 |
description: |
| 53 |
- Configure VNI information |
| 54 |
type: dict |
| 55 |
suboptions: |
| 56 |
l2vni: |
| 57 |
description: |
| 58 |
- Associates L2VNI with the VXLAN VTEP interface |
| 59 |
type: list |
| 60 |
elements: dict |
| 61 |
suboptions: |
| 62 |
vni: |
| 63 |
description: VNI number |
| 64 |
type: int |
| 65 |
replication: |
| 66 |
description: Replication type for the L2VNI |
| 67 |
type: dict |
| 68 |
suboptions: |
| 69 |
type: |
| 70 |
description: Replication type |
| 71 |
type: str |
| 72 |
choices: ['ingress', 'static'] |
| 73 |
mcast_group: |
| 74 |
description: Configure multicast group for VNI(s) |
| 75 |
type: dict |
| 76 |
suboptions: |
| 77 |
ipv4: |
| 78 |
description: IPv4 multicast group |
| 79 |
type: str |
| 80 |
ipv6: |
| 81 |
description: IPv6 multicast group |
| 82 |
type: str |
| 83 |
l3vni: |
| 84 |
description: |
| 85 |
- Associates L3VNI with the VXLAN VTEP interface |
| 86 |
type: list |
| 87 |
elements: dict |
| 88 |
suboptions: |
| 89 |
vni: |
| 90 |
description: VNI number |
| 91 |
type: int |
| 92 |
vrf: |
| 93 |
description: VRF name of the L3VNI |
| 94 |
type: str |
| 95 |
running_config: |
| 96 |
description: |
| 97 |
- This option is used only with state I(parsed). |
| 98 |
- The value of this option should be the output received from the IOS device by |
| 99 |
executing the command B(show running-config | section ^interface nve). |
| 100 |
- The state I(parsed) reads the configuration from C(running_config) option and |
| 101 |
transforms it into Ansible structured data as per the resource module's argspec |
| 102 |
and the value is then returned in the I(parsed) key within the result. |
| 103 |
type: str |
| 104 |
|
| 105 |
state: |
| 106 |
description: |
| 107 |
- The state the configuration should be left in |
| 108 |
type: str |
| 109 |
choices: |
| 110 |
- merged |
| 111 |
- replaced |
| 112 |
- overridden |
| 113 |
- deleted |
| 114 |
- rendered |
| 115 |
- gathered |
| 116 |
- parsed |
| 117 |
default: merged |
| 118 |
""" |
| 119 |
|
| 120 |
EXAMPLES = """ |
| 121 |
|
| 122 |
# Using state merged |
| 123 |
|
| 124 |
# Before state: |
| 125 |
# ------------- |
| 126 |
# interface nve1 |
| 127 |
# no ip address |
| 128 |
# source-interface Loopback1 |
| 129 |
# host-reachability protocol bgp |
| 130 |
# member vni 10101 mcast-group 225.0.0.101 |
| 131 |
# member vni 10102 ingress-replication |
| 132 |
# member vni 50901 vrf green |
| 133 |
# member vni 10201 mcast-group 225.0.0.101 |
| 134 |
# member vni 10202 ingress-replication |
| 135 |
# member vni 50902 vrf blue |
| 136 |
|
| 137 |
# - name: Merge the provided configuration with the device configuration |
| 138 |
# cisco.ios.ios_vxlan_vtep: |
| 139 |
# config: |
| 140 |
# - interface: nve1 |
| 141 |
# source_interface: loopback2 |
| 142 |
# member: |
| 143 |
# vni: |
| 144 |
# l2vni: |
| 145 |
# - vni: 10101 |
| 146 |
# replication: |
| 147 |
# type: ingress |
| 148 |
# - vni: 10201 |
| 149 |
# replication: |
| 150 |
# type: static |
| 151 |
# mcast_group: |
| 152 |
# ipv4: 225.0.0.101 |
| 153 |
# ipv6: FF0E:225::101 |
| 154 |
# l3vni: |
| 155 |
# - vni: 50901 |
| 156 |
# vrf: blue |
| 157 |
# state: merged |
| 158 |
|
| 159 |
# Commands Fired: |
| 160 |
# --------------- |
| 161 |
# "commands": [ |
| 162 |
# "interface nve1", |
| 163 |
# "source-interface loopback2", |
| 164 |
# "no member vni 10101 mcast-group 225.0.0.101", |
| 165 |
# "member vni 10101 ingress-replication", |
| 166 |
# "no member vni 10201 mcast-group 225.0.0.101", |
| 167 |
# "member vni 10201 mcast-group 225.0.0.101 FF0E:225::101", |
| 168 |
# "no member vni 50901 vrf green", |
| 169 |
# "no member vni 50902 vrf blue", |
| 170 |
# "member vni 50901 vrf blue" |
| 171 |
# ], |
| 172 |
|
| 173 |
# After state: |
| 174 |
# ------------ |
| 175 |
# interface nve1 |
| 176 |
# no ip address |
| 177 |
# source-interface Loopback2 |
| 178 |
# host-reachability protocol bgp |
| 179 |
# member vni 10102 ingress-replication |
| 180 |
# member vni 10202 ingress-replication |
| 181 |
# member vni 10101 ingress-replication |
| 182 |
# member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 |
| 183 |
# member vni 50901 vrf blue |
| 184 |
|
| 185 |
# Using state replaced |
| 186 |
|
| 187 |
# Before state: |
| 188 |
# ------------- |
| 189 |
# interface nve1 |
| 190 |
# no ip address |
| 191 |
# source-interface Loopback2 |
| 192 |
# host-reachability protocol bgp |
| 193 |
# member vni 10102 ingress-replication |
| 194 |
# member vni 10202 ingress-replication |
| 195 |
# member vni 10101 ingress-replication |
| 196 |
# member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 |
| 197 |
# member vni 50901 vrf blue |
| 198 |
|
| 199 |
# - name: Replaces the device configuration with the provided configuration |
| 200 |
# cisco.ios.ios_vxlan_vtep: |
| 201 |
# config: |
| 202 |
# - interface: nve1 |
| 203 |
# source_interface: Loopback2 |
| 204 |
# member: |
| 205 |
# vni: |
| 206 |
# l2vni: |
| 207 |
# - vni: 10101 |
| 208 |
# replication: |
| 209 |
# type: static |
| 210 |
# mcast_group: |
| 211 |
# ipv6: FF0E:225::101 |
| 212 |
# - vni: 10201 |
| 213 |
# replication: |
| 214 |
# type: static |
| 215 |
# mcast_group: |
| 216 |
# ipv6: FF0E:225::102 |
| 217 |
# state: replaced |
| 218 |
|
| 219 |
# Commands Fired: |
| 220 |
# --------------- |
| 221 |
# "commands": [ |
| 222 |
# "interface nve1", |
| 223 |
# "no member vni 10101 ingress-replication", |
| 224 |
# "member vni 10101 mcast-group FF0E:225::101", |
| 225 |
# "no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101", |
| 226 |
# "member vni 10201 mcast-group FF0E:225::102", |
| 227 |
# "no member vni 10102 ingress-replication", |
| 228 |
# "no member vni 10202 ingress-replication", |
| 229 |
# "no member vni 50901 vrf blue" |
| 230 |
# ], |
| 231 |
|
| 232 |
# After state: |
| 233 |
# ------------ |
| 234 |
# interface nve1 |
| 235 |
# no ip address |
| 236 |
# source-interface Loopback2 |
| 237 |
# host-reachability protocol bgp |
| 238 |
# member vni 10101 mcast-group FF0E:225::101 |
| 239 |
# member vni 10201 mcast-group FF0E:225::102 |
| 240 |
|
| 241 |
# Using state Deleted |
| 242 |
|
| 243 |
# Before state: |
| 244 |
# ------------- |
| 245 |
# interface nve1 |
| 246 |
# no ip address |
| 247 |
# source-interface Loopback2 |
| 248 |
# host-reachability protocol bgp |
| 249 |
# member vni 10101 mcast-group FF0E:225::101 |
| 250 |
# member vni 10201 mcast-group FF0E:225::102 |
| 251 |
|
| 252 |
# - name: "Delete VXLAN VTEP interface" |
| 253 |
# cisco.ios.ios_vxlan_vtep: |
| 254 |
# config: |
| 255 |
# - interface: nve1 |
| 256 |
# state: deleted |
| 257 |
|
| 258 |
# Commands Fired: |
| 259 |
# --------------- |
| 260 |
# "commands": [ |
| 261 |
# "interface nve1", |
| 262 |
# "no source-interface Loopback2", |
| 263 |
# "no host-reachability protocol bgp", |
| 264 |
# "no member vni 10101 mcast-group FF0E:225::101", |
| 265 |
# "no member vni 10201 mcast-group FF0E:225::102" |
| 266 |
# ], |
| 267 |
|
| 268 |
# After state: |
| 269 |
# ------------- |
| 270 |
# interface nve1 |
| 271 |
# no ip address |
| 272 |
|
| 273 |
# Using state Deleted with member VNIs |
| 274 |
|
| 275 |
# Before state: |
| 276 |
# ------------- |
| 277 |
# interface nve1 |
| 278 |
# no ip address |
| 279 |
# source-interface Loopback2 |
| 280 |
# host-reachability protocol bgp |
| 281 |
# member vni 10101 mcast-group FF0E:225::101 |
| 282 |
# member vni 10102 mcast-group 225.0.0.101 |
| 283 |
# member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 |
| 284 |
|
| 285 |
# - name: "Delete VXLAN VTEP interface with member VNIs" |
| 286 |
# cisco.ios.ios_vxlan_vtep: |
| 287 |
# config: |
| 288 |
# - interface: nve1 |
| 289 |
# source_interface: Loopback2 |
| 290 |
# member: |
| 291 |
# vni: |
| 292 |
# l2vni: |
| 293 |
# - vni: 10101 |
| 294 |
# - vni: 10102 |
| 295 |
# state: deleted |
| 296 |
|
| 297 |
# Commands Fired: |
| 298 |
# --------------- |
| 299 |
# "commands": [ |
| 300 |
# "interface nve1", |
| 301 |
# "no member vni 10101 mcast-group FF0E:225::101", |
| 302 |
# "no member vni 10102 mcast-group 225.0.0.101" |
| 303 |
# ], |
| 304 |
|
| 305 |
# After state: |
| 306 |
# ------------- |
| 307 |
# interface nve1 |
| 308 |
# no ip address |
| 309 |
# source-interface Loopback2 |
| 310 |
# host-reachability protocol bgp |
| 311 |
# member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 |
| 312 |
|
| 313 |
# Using state Deleted with no config |
| 314 |
|
| 315 |
# Before state: |
| 316 |
# ------------- |
| 317 |
# interface nve1 |
| 318 |
# no ip address |
| 319 |
# source-interface Loopback2 |
| 320 |
# host-reachability protocol bgp |
| 321 |
# member vni 10101 mcast-group FF0E:225::101 |
| 322 |
# member vni 10201 mcast-group FF0E:225::102 |
| 323 |
|
| 324 |
# - name: "Delete VXLAN VTEP interface with no config" |
| 325 |
# cisco.ios.ios_vxlan_vtep: |
| 326 |
# state: deleted |
| 327 |
|
| 328 |
# Commands Fired: |
| 329 |
# --------------- |
| 330 |
# "commands": [ |
| 331 |
# "interface nve1", |
| 332 |
# "no source-interface Loopback2", |
| 333 |
# "no host-reachability protocol bgp", |
| 334 |
# "no member vni 10101 mcast-group FF0E:225::101", |
| 335 |
# "no member vni 10201 mcast-group FF0E:225::102" |
| 336 |
# ], |
| 337 |
|
| 338 |
# After state: |
| 339 |
# ------------- |
| 340 |
# interface nve1 |
| 341 |
# no ip address |
| 342 |
""" |
| 343 |
|
| 344 |
RETURN = """ |
| 345 |
before: |
| 346 |
description: The configuration prior to the module execution. |
| 347 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 348 |
type: dict |
| 349 |
sample: > |
| 350 |
This output will always be in the same format as the |
| 351 |
module argspec. |
| 352 |
after: |
| 353 |
description: The resulting configuration after module execution. |
| 354 |
returned: when changed |
| 355 |
type: dict |
| 356 |
sample: > |
| 357 |
This output will always be in the same format as the |
| 358 |
module argspec. |
| 359 |
commands: |
| 360 |
description: The set of commands pushed to the remote device. |
| 361 |
returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) |
| 362 |
type: list |
| 363 |
sample: |
| 364 |
- 'interface nve1' |
| 365 |
- 'source-interface Loopback1' |
| 366 |
- 'host-reachability protocol bgp' |
| 367 |
- 'member vni 10101 ingress-replication' |
| 368 |
""" |
| 369 |
|
| 370 |
from ansible.module_utils.basic import AnsibleModule |
| 371 |
|
| 372 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.vxlan_vtep.vxlan_vtep import ( |
| 373 |
Vxlan_vtepArgs, |
| 374 |
) |
| 375 |
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.vxlan_vtep.vxlan_vtep import ( |
| 376 |
Vxlan_vtep, |
| 377 |
) |
| 378 |
|
| 379 |
|
| 380 |
def main(): |
| 381 |
""" |
| 382 |
Main entry point for module execution |
| 383 |
|
| 384 |
:returns: the result form module invocation |
| 385 |
""" |
| 386 |
module = AnsibleModule( |
| 387 |
argument_spec=Vxlan_vtepArgs.argument_spec, |
| 388 |
mutually_exclusive=[["config", "running_config"]], |
| 389 |
required_if=[ |
| 390 |
["state", "merged", ["config"]], |
| 391 |
["state", "replaced", ["config"]], |
| 392 |
["state", "overridden", ["config"]], |
| 393 |
["state", "rendered", ["config"]], |
| 394 |
["state", "parsed", ["running_config"]], |
| 395 |
], |
| 396 |
supports_check_mode=True, |
| 397 |
) |
| 398 |
|
| 399 |
result = Vxlan_vtep(module).execute_module() |
| 400 |
module.exit_json(**result) |
| 401 |
|
| 402 |
|
| 403 |
if __name__ == "__main__": |
| 404 |
main() |