| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2017, Jacob McGill (@jmcgill298) |
| 5 |
# Copyright: (c) 2024, Samita Bhattacharjee (@samitab) <[email protected]> |
| 6 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"} |
| 13 |
|
| 14 |
DOCUMENTATION = r""" |
| 15 |
--- |
| 16 |
module: aci_bd |
| 17 |
short_description: Manage Bridge Domains (BD) objects (fv:BD) |
| 18 |
description: |
| 19 |
- Manages Bridge Domains (BD) on Cisco ACI fabrics. |
| 20 |
options: |
| 21 |
arp_flooding: |
| 22 |
description: |
| 23 |
- Determines if the Bridge Domain should flood ARP traffic. |
| 24 |
- The APIC defaults to C(false) when unset during creation. |
| 25 |
type: bool |
| 26 |
bd: |
| 27 |
description: |
| 28 |
- The name of the Bridge Domain. |
| 29 |
type: str |
| 30 |
aliases: [ bd_name, name ] |
| 31 |
bd_type: |
| 32 |
description: |
| 33 |
- The type of traffic on the Bridge Domain. |
| 34 |
- The APIC defaults to C(ethernet) when unset during creation. |
| 35 |
type: str |
| 36 |
choices: [ ethernet, fc ] |
| 37 |
description: |
| 38 |
description: |
| 39 |
- Description for the Bridge Domain. |
| 40 |
type: str |
| 41 |
enable_multicast: |
| 42 |
description: |
| 43 |
- Determines if PIM is enabled. |
| 44 |
- The APIC defaults to C(false) when unset during creation. |
| 45 |
type: bool |
| 46 |
enable_routing: |
| 47 |
description: |
| 48 |
- Determines if IP forwarding should be allowed. |
| 49 |
- The APIC defaults to C(true) when unset during creation. |
| 50 |
type: bool |
| 51 |
endpoint_clear: |
| 52 |
description: |
| 53 |
- Clears all End Points in all Leaves when C(true). |
| 54 |
- The value is not reset to disabled once End Points have been cleared; that requires a second task. |
| 55 |
- The APIC defaults to C(false) when unset during creation. |
| 56 |
type: bool |
| 57 |
endpoint_move_detect: |
| 58 |
description: |
| 59 |
- Determines if GARP should be enabled to detect when End Points move. |
| 60 |
type: str |
| 61 |
choices: [ default, garp ] |
| 62 |
endpoint_retention_action: |
| 63 |
description: |
| 64 |
- Determines if the Bridge Domain should inherit or resolve the End Point Retention Policy. |
| 65 |
- The APIC defaults to C(resolve) when unset during creation. |
| 66 |
type: str |
| 67 |
choices: [ inherit, resolve ] |
| 68 |
endpoint_retention_policy: |
| 69 |
description: |
| 70 |
- The name of the End Point Retention Policy the Bridge Domain should use when |
| 71 |
overriding the default End Point Retention Policy. |
| 72 |
type: str |
| 73 |
igmp_snoop_policy: |
| 74 |
description: |
| 75 |
- The name of the IGMP Snooping Policy the Bridge Domain should use when |
| 76 |
overriding the default IGMP Snooping Policy. |
| 77 |
type: str |
| 78 |
ip_learning: |
| 79 |
description: |
| 80 |
- Determines if the Bridge Domain should learn End Point IPs. |
| 81 |
- The APIC defaults to C(true) when unset during creation. |
| 82 |
type: bool |
| 83 |
ipv6_nd_policy: |
| 84 |
description: |
| 85 |
- The name of the IPv6 Neighbor Discovery Policy the Bridge Domain should use when |
| 86 |
overridding the default IPV6 ND Policy. |
| 87 |
type: str |
| 88 |
l2_unknown_unicast: |
| 89 |
description: |
| 90 |
- Determines what forwarding method to use for unknown l2 destinations. |
| 91 |
- The APIC defaults to C(proxy) when unset during creation. |
| 92 |
type: str |
| 93 |
choices: [ proxy, flood ] |
| 94 |
l3_unknown_multicast: |
| 95 |
description: |
| 96 |
- Determines the forwarding method to use for unknown multicast destinations. |
| 97 |
- The APIC defaults to C(flood) when unset during creation. |
| 98 |
type: str |
| 99 |
choices: [ flood, opt-flood ] |
| 100 |
ipv6_l3_unknown_multicast: |
| 101 |
description: |
| 102 |
- Determines the forwarding method to use for IPv6 unknown multicast destinations. |
| 103 |
- The APIC defaults to C(flood) when unset during creation. |
| 104 |
type: str |
| 105 |
choices: [ flood, opt-flood ] |
| 106 |
limit_ip_learn: |
| 107 |
description: |
| 108 |
- Determines if the BD should limit IP learning to only subnets owned by the Bridge Domain. |
| 109 |
- The APIC defaults to C(true) when unset during creation. |
| 110 |
type: bool |
| 111 |
mac_address: |
| 112 |
description: |
| 113 |
- The MAC Address to assign to the C(bd) instead of using the default. |
| 114 |
- The APIC defaults to C(00:22:BD:F8:19:FF) when unset during creation. |
| 115 |
type: str |
| 116 |
aliases: [ mac ] |
| 117 |
multi_dest: |
| 118 |
description: |
| 119 |
- Determines the forwarding method for L2 multicast, broadcast, and link layer traffic. |
| 120 |
- The APIC defaults to C(bd-flood) when unset during creation. |
| 121 |
type: str |
| 122 |
choices: [ bd-flood, drop, encap-flood ] |
| 123 |
state: |
| 124 |
description: |
| 125 |
- Use C(present) or C(absent) for adding or removing. |
| 126 |
- Use C(query) for listing an object or multiple objects. |
| 127 |
type: str |
| 128 |
choices: [ absent, present, query ] |
| 129 |
default: present |
| 130 |
name_alias: |
| 131 |
description: |
| 132 |
- The alias for the current object. This relates to the nameAlias field in ACI. |
| 133 |
type: str |
| 134 |
tenant: |
| 135 |
description: |
| 136 |
- The name of the Tenant. |
| 137 |
type: str |
| 138 |
aliases: [ tenant_name ] |
| 139 |
vrf: |
| 140 |
description: |
| 141 |
- The name of the VRF. |
| 142 |
type: str |
| 143 |
aliases: [ vrf_name ] |
| 144 |
route_profile: |
| 145 |
description: |
| 146 |
- The Route Profile to associate with the Bridge Domain. |
| 147 |
type: str |
| 148 |
route_profile_l3out: |
| 149 |
description: |
| 150 |
- The L3 Out that contains the associated Route Profile. |
| 151 |
type: str |
| 152 |
host_based_routing: |
| 153 |
description: |
| 154 |
- Enables advertising host routes (/32 prefixes) out of the L3OUT(s) that are associated to this BD. |
| 155 |
- The APIC defaults to C(false) when unset during creation. |
| 156 |
type: bool |
| 157 |
aliases: [ advertise_host_routes ] |
| 158 |
enable_rogue_except_mac: |
| 159 |
description: |
| 160 |
- Rogue exception MAC wildcard support for Bridge Domains. |
| 161 |
- Only available in APIC version 6.0 or later. |
| 162 |
- The APIC defaults to C(false) when unset during creation. |
| 163 |
type: bool |
| 164 |
allow_intersite_bum_traffic: |
| 165 |
description: |
| 166 |
- Control whether BUM traffic is allowed between sites. |
| 167 |
- The APIC defaults to C(false) when unset during creation. |
| 168 |
type: bool |
| 169 |
aliases: [allow_bum_traffic] |
| 170 |
allow_intersite_l2_stretch: |
| 171 |
description: |
| 172 |
- Allow L2 Stretch between sites. |
| 173 |
- The APIC defaults to C(false) when unset during creation. |
| 174 |
type: bool |
| 175 |
aliases: [allow_l2_stretch] |
| 176 |
allow_ipv6_multicast: |
| 177 |
description: |
| 178 |
- Flag to indicate if ipv6 multicast is enabled. |
| 179 |
- The APIC defaults to C(false) when unset during creation. |
| 180 |
type: bool |
| 181 |
aliases: [ ipv6_multicast, ipv6_mcast, allow_ipv6_mcast] |
| 182 |
link_local_address: |
| 183 |
description: |
| 184 |
- The override of the system generated IPv6 link-local address. |
| 185 |
type: str |
| 186 |
aliases: [ ll_addr_ipv6, ll_addr, link_local] |
| 187 |
multicast_arp_drop: |
| 188 |
description: |
| 189 |
- Enable BD rogue multicast ARP packet drop. |
| 190 |
- Only available in APIC version 6.0 or later. |
| 191 |
- The APIC defaults to C(true) when unset during creation. |
| 192 |
type: bool |
| 193 |
aliases: [ mcast_arp_drop ] |
| 194 |
vmac: |
| 195 |
description: |
| 196 |
- Virtual MAC address of the BD/SVI. This is used when the BD is extended to multiple sites using L2 Outside. |
| 197 |
type: str |
| 198 |
optimize_wan_bandwidth: |
| 199 |
description: |
| 200 |
- Optimize WAN Bandwidth improves the network application experience at the branch and makes better use of limited network resources. |
| 201 |
- The APIC defaults to C(false) when unset during creation. |
| 202 |
type: bool |
| 203 |
aliases: [wan_optimization, opt_bandwidth] |
| 204 |
mld_snoop_policy: |
| 205 |
description: |
| 206 |
- The name of the Multicast Listener Discovery (MLD) Snooping Policy the Bridge Domain should use when overriding the default MLD Snooping Policy. |
| 207 |
- To delete this attribute, pass an empty string. |
| 208 |
type: str |
| 209 |
aliases: [mld_snoop, mld_policy] |
| 210 |
igmp_policy: |
| 211 |
description: |
| 212 |
- The name of the IGMP Interface Policy the Bridge Domain should use when overriding the default IGMP Interface Policy. |
| 213 |
- To delete this attribute, pass an empty string. |
| 214 |
type: str |
| 215 |
aliases: [igmp] |
| 216 |
vlan: |
| 217 |
description: |
| 218 |
- The selected VLAN for bridge domain access port encapsulation. |
| 219 |
- To delete this attribute, pass an empty string. |
| 220 |
type: str |
| 221 |
aliases: [encap] |
| 222 |
monitoring_policy: |
| 223 |
description: |
| 224 |
- The name of the Monitoring Policy to apply to the Bridge Domain. |
| 225 |
- To delete this attribute, pass an empty string. |
| 226 |
type: str |
| 227 |
aliases: [mon_pol, monitoring_pol] |
| 228 |
first_hop_security_policy: |
| 229 |
description: |
| 230 |
- The name of the First Hop Security Policy to apply to the Bridge Domain. |
| 231 |
- To delete this attribute, pass an empty string. |
| 232 |
type: str |
| 233 |
aliases: [fhsp, fhs_pol, fhsp_name] |
| 234 |
pim_source_filter: |
| 235 |
description: |
| 236 |
- The name of the PIM Source Filter to apply to the Bridge Domain. |
| 237 |
- To delete this attribute, pass an empty string. |
| 238 |
- Only available in APIC version 5.2 or later. |
| 239 |
type: str |
| 240 |
aliases: [pim_source] |
| 241 |
pim_destination_filter: |
| 242 |
description: |
| 243 |
- The name of the PIM Destination Filter to apply to the Bridge Domain. |
| 244 |
- To delete this attribute, pass an empty string. |
| 245 |
- Only available in APIC version 5.2 or later. |
| 246 |
type: str |
| 247 |
aliases: [pim_dest, pim_destination] |
| 248 |
|
| 249 |
extends_documentation_fragment: |
| 250 |
- cisco.aci.aci |
| 251 |
- cisco.aci.annotation |
| 252 |
- cisco.aci.owner |
| 253 |
|
| 254 |
notes: |
| 255 |
- The C(tenant) used must exist before using this module in your playbook. |
| 256 |
The M(cisco.aci.aci_tenant) module can be used for this. |
| 257 |
seealso: |
| 258 |
- module: cisco.aci.aci_tenant |
| 259 |
- name: APIC Management Information Model reference |
| 260 |
description: More information about the internal APIC class B(fv:BD). |
| 261 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 262 |
author: |
| 263 |
- Jacob McGill (@jmcgill298) |
| 264 |
- Samita Bhattacharjee (@samitab) |
| 265 |
""" |
| 266 |
|
| 267 |
EXAMPLES = r""" |
| 268 |
- name: Add Bridge Domain |
| 269 |
cisco.aci.aci_bd: |
| 270 |
host: "{{ inventory_hostname }}" |
| 271 |
username: "{{ username }}" |
| 272 |
password: "{{ password }}" |
| 273 |
validate_certs: false |
| 274 |
tenant: prod |
| 275 |
bd: web_servers |
| 276 |
mac_address: 00:22:BD:F8:19:FE |
| 277 |
vrf: prod_vrf |
| 278 |
host_based_routing: true |
| 279 |
allow_intersite_bum_traffic: true |
| 280 |
allow_intersite_l2_stretch: true |
| 281 |
allow_ipv6_mcast: true |
| 282 |
ll_addr: "fe80::1322:33ff:fe44:5566" |
| 283 |
vmac: "00:AA:BB:CC:DD:03" |
| 284 |
optimize_wan_bandwidth: true |
| 285 |
vlan: vlan-101 |
| 286 |
igmp_policy: web_servers_igmp_pol |
| 287 |
monitoring_policy: web_servers_monitoring_pol |
| 288 |
igmp_snoop_policy: web_servers_igmp_snoop |
| 289 |
mld_snoop_policy: web_servers_mld_snoop |
| 290 |
first_hop_security_policy: web_servers_fhs |
| 291 |
state: present |
| 292 |
delegate_to: localhost |
| 293 |
|
| 294 |
- name: Add an FC Bridge Domain |
| 295 |
cisco.aci.aci_bd: |
| 296 |
host: "{{ inventory_hostname }}" |
| 297 |
username: "{{ username }}" |
| 298 |
password: "{{ password }}" |
| 299 |
validate_certs: false |
| 300 |
tenant: prod |
| 301 |
bd: storage |
| 302 |
bd_type: fc |
| 303 |
vrf: fc_vrf |
| 304 |
enable_routing: false |
| 305 |
state: present |
| 306 |
delegate_to: localhost |
| 307 |
|
| 308 |
- name: Modify a Bridge Domain |
| 309 |
cisco.aci.aci_bd: |
| 310 |
host: "{{ inventory_hostname }}" |
| 311 |
username: "{{ username }}" |
| 312 |
password: "{{ password }}" |
| 313 |
validate_certs: true |
| 314 |
tenant: prod |
| 315 |
bd: web_servers |
| 316 |
arp_flooding: true |
| 317 |
l2_unknown_unicast: flood |
| 318 |
state: present |
| 319 |
delegate_to: localhost |
| 320 |
|
| 321 |
- name: Modify a Bridge Domain to remove mld_snoop_policy and first_hop_security_policy |
| 322 |
cisco.aci.aci_bd: |
| 323 |
host: "{{ inventory_hostname }}" |
| 324 |
username: "{{ username }}" |
| 325 |
password: "{{ password }}" |
| 326 |
validate_certs: true |
| 327 |
tenant: prod |
| 328 |
bd: web_servers |
| 329 |
arp_flooding: true |
| 330 |
l2_unknown_unicast: flood |
| 331 |
mld_snoop_policy: "" |
| 332 |
first_hop_security_policy: "" |
| 333 |
state: present |
| 334 |
delegate_to: localhost |
| 335 |
|
| 336 |
- name: Query All Bridge Domains |
| 337 |
cisco.aci.aci_bd: |
| 338 |
host: "{{ inventory_hostname }}" |
| 339 |
username: "{{ username }}" |
| 340 |
password: "{{ password }}" |
| 341 |
validate_certs: true |
| 342 |
state: query |
| 343 |
delegate_to: localhost |
| 344 |
register: query_result |
| 345 |
|
| 346 |
- name: Query a Bridge Domain |
| 347 |
cisco.aci.aci_bd: |
| 348 |
host: "{{ inventory_hostname }}" |
| 349 |
username: "{{ username }}" |
| 350 |
password: "{{ password }}" |
| 351 |
validate_certs: true |
| 352 |
tenant: prod |
| 353 |
bd: web_servers |
| 354 |
state: query |
| 355 |
delegate_to: localhost |
| 356 |
register: query_result |
| 357 |
|
| 358 |
- name: Delete a Bridge Domain |
| 359 |
cisco.aci.aci_bd: |
| 360 |
host: "{{ inventory_hostname }}" |
| 361 |
username: "{{ username }}" |
| 362 |
password: "{{ password }}" |
| 363 |
validate_certs: true |
| 364 |
tenant: prod |
| 365 |
bd: web_servers |
| 366 |
state: absent |
| 367 |
delegate_to: localhost |
| 368 |
""" |
| 369 |
|
| 370 |
RETURN = r""" |
| 371 |
current: |
| 372 |
description: The existing configuration from the APIC after the module has finished |
| 373 |
returned: success |
| 374 |
type: list |
| 375 |
sample: |
| 376 |
[ |
| 377 |
{ |
| 378 |
"fvTenant": { |
| 379 |
"attributes": { |
| 380 |
"descr": "Production environment", |
| 381 |
"dn": "uni/tn-production", |
| 382 |
"name": "production", |
| 383 |
"nameAlias": "", |
| 384 |
"ownerKey": "", |
| 385 |
"ownerTag": "" |
| 386 |
} |
| 387 |
} |
| 388 |
} |
| 389 |
] |
| 390 |
error: |
| 391 |
description: The error information as returned from the APIC |
| 392 |
returned: failure |
| 393 |
type: dict |
| 394 |
sample: |
| 395 |
{ |
| 396 |
"code": "122", |
| 397 |
"text": "unknown managed object class foo" |
| 398 |
} |
| 399 |
raw: |
| 400 |
description: The raw output returned by the APIC REST API (xml or json) |
| 401 |
returned: parse error |
| 402 |
type: str |
| 403 |
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>' |
| 404 |
sent: |
| 405 |
description: The actual/minimal configuration pushed to the APIC |
| 406 |
returned: info |
| 407 |
type: list |
| 408 |
sample: |
| 409 |
{ |
| 410 |
"fvTenant": { |
| 411 |
"attributes": { |
| 412 |
"descr": "Production environment" |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
previous: |
| 417 |
description: The original configuration from the APIC before the module has started |
| 418 |
returned: info |
| 419 |
type: list |
| 420 |
sample: |
| 421 |
[ |
| 422 |
{ |
| 423 |
"fvTenant": { |
| 424 |
"attributes": { |
| 425 |
"descr": "Production", |
| 426 |
"dn": "uni/tn-production", |
| 427 |
"name": "production", |
| 428 |
"nameAlias": "", |
| 429 |
"ownerKey": "", |
| 430 |
"ownerTag": "" |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
] |
| 435 |
proposed: |
| 436 |
description: The assembled configuration from the user-provided parameters |
| 437 |
returned: info |
| 438 |
type: dict |
| 439 |
sample: |
| 440 |
{ |
| 441 |
"fvTenant": { |
| 442 |
"attributes": { |
| 443 |
"descr": "Production environment", |
| 444 |
"name": "production" |
| 445 |
} |
| 446 |
} |
| 447 |
} |
| 448 |
filter_string: |
| 449 |
description: The filter string used for the request |
| 450 |
returned: failure or debug |
| 451 |
type: str |
| 452 |
sample: ?rsp-prop-include=config-only |
| 453 |
method: |
| 454 |
description: The HTTP method used for the request to the APIC |
| 455 |
returned: failure or debug |
| 456 |
type: str |
| 457 |
sample: POST |
| 458 |
response: |
| 459 |
description: The HTTP response from the APIC |
| 460 |
returned: failure or debug |
| 461 |
type: str |
| 462 |
sample: OK (30 bytes) |
| 463 |
status: |
| 464 |
description: The HTTP status from the APIC |
| 465 |
returned: failure or debug |
| 466 |
type: int |
| 467 |
sample: 200 |
| 468 |
url: |
| 469 |
description: The HTTP url used for the request to the APIC |
| 470 |
returned: failure or debug |
| 471 |
type: str |
| 472 |
sample: https://10.11.12.13/api/mo/uni/tn-production.json |
| 473 |
""" |
| 474 |
|
| 475 |
from ansible.module_utils.basic import AnsibleModule |
| 476 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec |
| 477 |
|
| 478 |
|
| 479 |
def main(): |
| 480 |
argument_spec = aci_argument_spec() |
| 481 |
argument_spec.update(aci_annotation_spec()) |
| 482 |
argument_spec.update(aci_owner_spec()) |
| 483 |
argument_spec.update( |
| 484 |
arp_flooding=dict(type="bool"), |
| 485 |
bd=dict(type="str", aliases=["bd_name", "name"]), # Not required for querying all objects |
| 486 |
bd_type=dict(type="str", choices=["ethernet", "fc"]), |
| 487 |
description=dict(type="str"), |
| 488 |
enable_multicast=dict(type="bool"), |
| 489 |
enable_routing=dict(type="bool"), |
| 490 |
endpoint_clear=dict(type="bool"), |
| 491 |
endpoint_move_detect=dict(type="str", choices=["default", "garp"]), |
| 492 |
endpoint_retention_action=dict(type="str", choices=["inherit", "resolve"]), |
| 493 |
endpoint_retention_policy=dict(type="str"), |
| 494 |
igmp_snoop_policy=dict(type="str"), |
| 495 |
ip_learning=dict(type="bool"), |
| 496 |
ipv6_nd_policy=dict(type="str"), |
| 497 |
l2_unknown_unicast=dict(type="str", choices=["proxy", "flood"]), |
| 498 |
l3_unknown_multicast=dict(type="str", choices=["flood", "opt-flood"]), |
| 499 |
ipv6_l3_unknown_multicast=dict(type="str", choices=["flood", "opt-flood"]), |
| 500 |
limit_ip_learn=dict(type="bool"), |
| 501 |
mac_address=dict(type="str", aliases=["mac"]), |
| 502 |
multi_dest=dict(type="str", choices=["bd-flood", "drop", "encap-flood"]), |
| 503 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 504 |
tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects |
| 505 |
vrf=dict(type="str", aliases=["vrf_name"]), |
| 506 |
route_profile=dict(type="str"), |
| 507 |
route_profile_l3out=dict(type="str"), |
| 508 |
name_alias=dict(type="str"), |
| 509 |
host_based_routing=dict(type="bool", aliases=["advertise_host_routes"]), |
| 510 |
enable_rogue_except_mac=dict(type="bool"), |
| 511 |
allow_intersite_bum_traffic=dict(type="bool", aliases=["allow_bum_traffic"]), |
| 512 |
allow_intersite_l2_stretch=dict(type="bool", aliases=["allow_l2_stretch"]), |
| 513 |
allow_ipv6_multicast=dict(type="bool", aliases=["ipv6_multicast", "ipv6_mcast", "allow_ipv6_mcast"]), |
| 514 |
link_local_address=dict(type="str", aliases=["ll_addr_ipv6", "ll_addr", "link_local"]), |
| 515 |
multicast_arp_drop=dict(type="bool", aliases=["mcast_arp_drop"]), |
| 516 |
vmac=dict(type="str"), |
| 517 |
optimize_wan_bandwidth=dict(type="bool", aliases=["wan_optimization", "opt_bandwidth"]), |
| 518 |
mld_snoop_policy=dict(type="str", aliases=["mld_snoop", "mld_policy"]), |
| 519 |
igmp_policy=dict(type="str", aliases=["igmp"]), |
| 520 |
vlan=dict(type="str", aliases=["encap"]), |
| 521 |
monitoring_policy=dict(type="str", aliases=["mon_pol", "monitoring_pol"]), |
| 522 |
first_hop_security_policy=dict(type="str", aliases=["fhsp", "fhs_pol", "fhsp_name"]), |
| 523 |
pim_source_filter=dict(type="str", aliases=["pim_source"]), |
| 524 |
pim_destination_filter=dict(type="str", aliases=["pim_dest", "pim_destination"]), |
| 525 |
) |
| 526 |
|
| 527 |
module = AnsibleModule( |
| 528 |
argument_spec=argument_spec, |
| 529 |
supports_check_mode=True, |
| 530 |
required_if=[ |
| 531 |
["state", "absent", ["bd", "tenant"]], |
| 532 |
["state", "present", ["bd", "tenant"]], |
| 533 |
], |
| 534 |
) |
| 535 |
|
| 536 |
aci = ACIModule(module) |
| 537 |
|
| 538 |
arp_flooding = aci.boolean(module.params.get("arp_flooding")) |
| 539 |
bd = module.params.get("bd") |
| 540 |
bd_type = module.params.get("bd_type") |
| 541 |
if bd_type == "ethernet": |
| 542 |
# ethernet type is represented as regular, but that is not clear to the users |
| 543 |
bd_type = "regular" |
| 544 |
description = module.params.get("description") |
| 545 |
enable_multicast = aci.boolean(module.params.get("enable_multicast")) |
| 546 |
enable_routing = aci.boolean(module.params.get("enable_routing")) |
| 547 |
endpoint_clear = aci.boolean(module.params.get("endpoint_clear")) |
| 548 |
endpoint_move_detect = module.params.get("endpoint_move_detect") |
| 549 |
if endpoint_move_detect == "default": |
| 550 |
# the ACI default setting is an empty string, but that is not a good input value |
| 551 |
endpoint_move_detect = "" |
| 552 |
endpoint_retention_action = module.params.get("endpoint_retention_action") |
| 553 |
endpoint_retention_policy = module.params.get("endpoint_retention_policy") |
| 554 |
igmp_snoop_policy = module.params.get("igmp_snoop_policy") |
| 555 |
ip_learning = aci.boolean(module.params.get("ip_learning")) |
| 556 |
ipv6_nd_policy = module.params.get("ipv6_nd_policy") |
| 557 |
l2_unknown_unicast = module.params.get("l2_unknown_unicast") |
| 558 |
l3_unknown_multicast = module.params.get("l3_unknown_multicast") |
| 559 |
ipv6_l3_unknown_multicast = module.params.get("ipv6_l3_unknown_multicast") |
| 560 |
limit_ip_learn = aci.boolean(module.params.get("limit_ip_learn")) |
| 561 |
mac_address = module.params.get("mac_address") |
| 562 |
multi_dest = module.params.get("multi_dest") |
| 563 |
state = module.params.get("state") |
| 564 |
tenant = module.params.get("tenant") |
| 565 |
vrf = module.params.get("vrf") |
| 566 |
route_profile = module.params.get("route_profile") |
| 567 |
route_profile_l3out = module.params.get("route_profile_l3out") |
| 568 |
name_alias = module.params.get("name_alias") |
| 569 |
host_based_routing = aci.boolean(module.params.get("host_based_routing")) |
| 570 |
enable_rogue_except_mac = aci.boolean(module.params.get("enable_rogue_except_mac")) |
| 571 |
allow_intersite_bum_traffic = aci.boolean(module.params.get("allow_intersite_bum_traffic")) |
| 572 |
allow_intersite_l2_stretch = aci.boolean(module.params.get("allow_intersite_l2_stretch")) |
| 573 |
allow_ipv6_multicast = aci.boolean(module.params.get("allow_ipv6_multicast")) |
| 574 |
link_local_address = module.params.get("link_local_address") |
| 575 |
multicast_arp_drop = aci.boolean(module.params.get("multicast_arp_drop")) |
| 576 |
vmac = module.params.get("vmac") |
| 577 |
optimize_wan_bandwidth = aci.boolean(module.params.get("optimize_wan_bandwidth")) |
| 578 |
mld_snoop_policy = module.params.get("mld_snoop_policy") |
| 579 |
igmp_policy = module.params.get("igmp_policy") |
| 580 |
vlan = module.params.get("vlan") |
| 581 |
monitoring_policy = module.params.get("monitoring_policy") |
| 582 |
first_hop_security_policy = module.params.get("first_hop_security_policy") |
| 583 |
pim_source_filter = module.params.get("pim_source_filter") |
| 584 |
pim_destination_filter = module.params.get("pim_destination_filter") |
| 585 |
|
| 586 |
child_classes = [ |
| 587 |
"fvRsCtx", |
| 588 |
"fvRsIgmpsn", |
| 589 |
"fvRsBDToNdP", |
| 590 |
"fvRsBdToEpRet", |
| 591 |
"fvRsBDToProfile", |
| 592 |
"fvRsMldsn", |
| 593 |
"igmpIfP", |
| 594 |
"igmpRsIfPol", |
| 595 |
"fvAccP", |
| 596 |
"fvRsABDPolMonPol", |
| 597 |
"fvRsBDToFhs", |
| 598 |
] |
| 599 |
if pim_source_filter is not None or pim_destination_filter is not None: |
| 600 |
# Only valid for APIC verion 5.2+ |
| 601 |
child_classes.extend( |
| 602 |
[ |
| 603 |
"pimBDP", |
| 604 |
"pimBDFilterPol", |
| 605 |
"pimBDSrcFilterPol", |
| 606 |
"pimBDDestFilterPol", |
| 607 |
"rtdmcRsFilterToRtMapPol", |
| 608 |
] |
| 609 |
) |
| 610 |
aci.construct_url( |
| 611 |
root_class=dict( |
| 612 |
aci_class="fvTenant", |
| 613 |
aci_rn="tn-{0}".format(tenant), |
| 614 |
module_object=tenant, |
| 615 |
target_filter={"name": tenant}, |
| 616 |
), |
| 617 |
subclass_1=dict( |
| 618 |
aci_class="fvBD", |
| 619 |
aci_rn="BD-{0}".format(bd), |
| 620 |
module_object=bd, |
| 621 |
target_filter={"name": bd}, |
| 622 |
), |
| 623 |
child_classes=child_classes, |
| 624 |
) |
| 625 |
|
| 626 |
aci.get_existing() |
| 627 |
|
| 628 |
if state == "present": |
| 629 |
class_config = dict( |
| 630 |
arpFlood=arp_flooding, |
| 631 |
descr=description, |
| 632 |
epClear=endpoint_clear, |
| 633 |
epMoveDetectMode=endpoint_move_detect, |
| 634 |
ipLearning=ip_learning, |
| 635 |
limitIpLearnToSubnets=limit_ip_learn, |
| 636 |
mac=mac_address, |
| 637 |
mcastAllow=enable_multicast, |
| 638 |
multiDstPktAct=multi_dest, |
| 639 |
name=bd, |
| 640 |
type=bd_type, |
| 641 |
unicastRoute=enable_routing, |
| 642 |
unkMacUcastAct=l2_unknown_unicast, |
| 643 |
unkMcastAct=l3_unknown_multicast, |
| 644 |
nameAlias=name_alias, |
| 645 |
enableRogueExceptMac=enable_rogue_except_mac, |
| 646 |
hostBasedRouting=host_based_routing, |
| 647 |
intersiteBumTrafficAllow=allow_intersite_bum_traffic, |
| 648 |
intersiteL2Stretch=allow_intersite_l2_stretch, |
| 649 |
ipv6McastAllow=allow_ipv6_multicast, |
| 650 |
llAddr=link_local_address, |
| 651 |
mcastARPDrop=multicast_arp_drop, |
| 652 |
vmac=vmac, |
| 653 |
OptimizeWanBandwidth=optimize_wan_bandwidth, |
| 654 |
) |
| 655 |
|
| 656 |
if ipv6_l3_unknown_multicast is not None: |
| 657 |
class_config["v6unkMcastAct"] = ipv6_l3_unknown_multicast |
| 658 |
|
| 659 |
child_configs = [ |
| 660 |
{"fvRsCtx": {"attributes": {"tnFvCtxName": vrf}}}, |
| 661 |
{"fvRsIgmpsn": {"attributes": {"tnIgmpSnoopPolName": igmp_snoop_policy}}}, |
| 662 |
{"fvRsMldsn": {"attributes": {"tnMldSnoopPolName": mld_snoop_policy}}}, |
| 663 |
{"fvRsBDToNdP": {"attributes": {"tnNdIfPolName": ipv6_nd_policy}}}, |
| 664 |
{"fvRsBdToEpRet": {"attributes": {"resolveAct": endpoint_retention_action, "tnFvEpRetPolName": endpoint_retention_policy}}}, |
| 665 |
{"fvRsBDToProfile": {"attributes": {"tnL3extOutName": route_profile_l3out, "tnRtctrlProfileName": route_profile}}}, |
| 666 |
{"fvRsBDToFhs": {"attributes": {"tnFhsBDPolName": first_hop_security_policy}}}, |
| 667 |
{"fvAccP": {"attributes": {"encap": vlan}}}, |
| 668 |
{"fvRsABDPolMonPol": {"attributes": {"tnMonEPGPolName": monitoring_policy}}}, |
| 669 |
] |
| 670 |
|
| 671 |
if igmp_policy is not None: |
| 672 |
igmp_policy_tdn = "" if igmp_policy == "" else "uni/tn-{0}/igmpIfPol-{1}".format(tenant, igmp_policy) |
| 673 |
child_configs.append({"igmpIfP": {"attributes": {}, "children": [{"igmpRsIfPol": {"attributes": {"tDn": igmp_policy_tdn}}}]}}) |
| 674 |
if pim_source_filter is not None or pim_destination_filter is not None: |
| 675 |
pim_bd = {"pimBDP": {"attributes": {}, "children": []}} |
| 676 |
pim_filter_pol = {"pimBDFilterPol": {"attributes": {}, "children": []}} |
| 677 |
if pim_source_filter is not None: |
| 678 |
pim_source_filter_tdn = "" if pim_source_filter == "" else "uni/tn-{0}/rtmap-{1}".format(tenant, pim_source_filter) |
| 679 |
pim_filter_pol["pimBDFilterPol"]["children"].append( |
| 680 |
{"pimBDSrcFilterPol": {"attributes": {}, "children": [{"rtdmcRsFilterToRtMapPol": {"attributes": {"tDn": pim_source_filter_tdn}}}]}} |
| 681 |
) |
| 682 |
if pim_destination_filter is not None: |
| 683 |
pim_destination_filter_tdn = "" if pim_destination_filter == "" else "uni/tn-{0}/rtmap-{1}".format(tenant, pim_destination_filter) |
| 684 |
pim_filter_pol["pimBDFilterPol"]["children"].append( |
| 685 |
{"pimBDDestFilterPol": {"attributes": {}, "children": [{"rtdmcRsFilterToRtMapPol": {"attributes": {"tDn": pim_destination_filter_tdn}}}]}} |
| 686 |
) |
| 687 |
pim_bd["pimBDP"]["children"].append(pim_filter_pol) |
| 688 |
child_configs.append(pim_bd) |
| 689 |
|
| 690 |
aci.payload(aci_class="fvBD", class_config=class_config, child_configs=child_configs) |
| 691 |
|
| 692 |
aci.get_diff(aci_class="fvBD") |
| 693 |
|
| 694 |
aci.post_config() |
| 695 |
|
| 696 |
elif state == "absent": |
| 697 |
aci.delete_config() |
| 698 |
|
| 699 |
aci.exit_json() |
| 700 |
|
| 701 |
|
| 702 |
if __name__ == "__main__": |
| 703 |
main() |