| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2018, Kevin Breit (@kbreit) <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = { |
| 12 |
"metadata_version": "1.1", |
| 13 |
"status": ["deprecated"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
author: |
| 19 |
- Kevin Breit (@kbreit) |
| 20 |
deprecated: |
| 21 |
alternative: cisco.meraki.networks_wireless_ssids |
| 22 |
removed_in: 3.0.0 |
| 23 |
why: Updated modules released with increased functionality |
| 24 |
description: |
| 25 |
- Allows for management of SSIDs in a Meraki wireless environment. |
| 26 |
extends_documentation_fragment: cisco.meraki.meraki |
| 27 |
module: meraki_mr_ssid |
| 28 |
notes: |
| 29 |
- Deleting an SSID does not delete RADIUS servers. |
| 30 |
options: |
| 31 |
ap_availability_tags: |
| 32 |
description: |
| 33 |
- Set whether SSID will be broadcast by APs with tags matching any of the tags |
| 34 |
in this list. |
| 35 |
- Requires C(available_on_all_aps) to be C(false). |
| 36 |
elements: str |
| 37 |
type: list |
| 38 |
ap_tags_vlan_ids: |
| 39 |
description: |
| 40 |
- List of VLAN tags. |
| 41 |
- Requires C(ip_assignment_mode) to be C(Bridge mode) or C(Layer 3 roaming). |
| 42 |
- Requires C(use_vlan_tagging) to be C(True). |
| 43 |
elements: dict |
| 44 |
suboptions: |
| 45 |
tags: |
| 46 |
description: |
| 47 |
- List of AP tags. |
| 48 |
elements: str |
| 49 |
type: list |
| 50 |
vlan_id: |
| 51 |
description: |
| 52 |
- Numerical identifier that is assigned to the VLAN. |
| 53 |
type: int |
| 54 |
type: list |
| 55 |
auth_mode: |
| 56 |
choices: |
| 57 |
- open |
| 58 |
- psk |
| 59 |
- open-with-radius |
| 60 |
- 8021x-meraki |
| 61 |
- 8021x-radius |
| 62 |
description: |
| 63 |
- Set authentication mode of network. |
| 64 |
type: str |
| 65 |
available_on_all_aps: |
| 66 |
description: |
| 67 |
- Set whether all APs should broadcast the SSID or if it should be restricted |
| 68 |
to APs matching any availability tags. |
| 69 |
- Requires C(ap_availability_tags) to be defined when set to C(False). |
| 70 |
type: bool |
| 71 |
band_selection: |
| 72 |
choices: |
| 73 |
- Dual band operation |
| 74 |
- 5 GHz band only |
| 75 |
- Dual band operation with Band Steering |
| 76 |
description: |
| 77 |
- Set band selection mode. |
| 78 |
type: str |
| 79 |
concentrator_network_id: |
| 80 |
description: |
| 81 |
- The concentrator to use for 'Layer 3 roaming with a concentrator' or 'VPN'. |
| 82 |
type: str |
| 83 |
default_vlan_id: |
| 84 |
description: |
| 85 |
- Default VLAN ID. |
| 86 |
- Requires C(ip_assignment_mode) to be C(Bridge mode) or C(Layer 3 roaming). |
| 87 |
type: int |
| 88 |
enabled: |
| 89 |
description: |
| 90 |
- Enable or disable SSID network. |
| 91 |
type: bool |
| 92 |
encryption_mode: |
| 93 |
choices: |
| 94 |
- wpa |
| 95 |
- eap |
| 96 |
- wpa-eap |
| 97 |
description: |
| 98 |
- Set encryption mode of network. |
| 99 |
type: str |
| 100 |
enterprise_admin_access: |
| 101 |
choices: |
| 102 |
- access disabled |
| 103 |
- access enabled |
| 104 |
description: |
| 105 |
- Whether SSID is accessible by enterprise administrators. |
| 106 |
type: str |
| 107 |
ip_assignment_mode: |
| 108 |
choices: |
| 109 |
- NAT mode |
| 110 |
- Bridge mode |
| 111 |
- Layer 3 roaming |
| 112 |
- Layer 3 roaming with a concentrator |
| 113 |
- VPN |
| 114 |
description: |
| 115 |
- Method of which SSID uses to assign IP addresses. |
| 116 |
type: str |
| 117 |
lan_isolation_enabled: |
| 118 |
description: |
| 119 |
- Enable or disable Layer 2 Lan isolation. |
| 120 |
- Requires C(ip_assignment_mode) to be C(Bridge mode). |
| 121 |
type: bool |
| 122 |
min_bitrate: |
| 123 |
choices: |
| 124 |
- 1 |
| 125 |
- 2 |
| 126 |
- 5.5 |
| 127 |
- 6 |
| 128 |
- 9 |
| 129 |
- 11 |
| 130 |
- 12 |
| 131 |
- 18 |
| 132 |
- 24 |
| 133 |
- 36 |
| 134 |
- 48 |
| 135 |
- 54 |
| 136 |
description: |
| 137 |
- Minimum bitrate (Mbps) allowed on SSID. |
| 138 |
type: float |
| 139 |
name: |
| 140 |
description: |
| 141 |
- Name of SSID. |
| 142 |
type: str |
| 143 |
net_id: |
| 144 |
description: |
| 145 |
- ID of network. |
| 146 |
type: str |
| 147 |
net_name: |
| 148 |
description: |
| 149 |
- Name of network. |
| 150 |
type: str |
| 151 |
number: |
| 152 |
aliases: |
| 153 |
- ssid_number |
| 154 |
description: |
| 155 |
- SSID number within network. |
| 156 |
type: int |
| 157 |
per_client_bandwidth_limit_down: |
| 158 |
description: |
| 159 |
- Maximum bandwidth in Mbps devices on SSID can download. |
| 160 |
type: int |
| 161 |
per_client_bandwidth_limit_up: |
| 162 |
description: |
| 163 |
- Maximum bandwidth in Mbps devices on SSID can upload. |
| 164 |
type: int |
| 165 |
psk: |
| 166 |
description: |
| 167 |
- Password for wireless network. |
| 168 |
- Requires auth_mode to be set to psk. |
| 169 |
type: str |
| 170 |
radius_accounting_enabled: |
| 171 |
description: |
| 172 |
- Enable or disable RADIUS accounting. |
| 173 |
type: bool |
| 174 |
radius_accounting_servers: |
| 175 |
description: |
| 176 |
- List of RADIUS servers for RADIUS accounting. |
| 177 |
elements: dict |
| 178 |
suboptions: |
| 179 |
host: |
| 180 |
description: |
| 181 |
- IP address or hostname of RADIUS server. |
| 182 |
required: true |
| 183 |
type: str |
| 184 |
port: |
| 185 |
description: |
| 186 |
- Port number RADIUS server is listening to. |
| 187 |
type: int |
| 188 |
secret: |
| 189 |
description: |
| 190 |
- RADIUS password. |
| 191 |
- Setting password is not idempotent. |
| 192 |
type: str |
| 193 |
type: list |
| 194 |
radius_coa_enabled: |
| 195 |
description: |
| 196 |
- Enable or disable RADIUS CoA (Change of Authorization) on SSID. |
| 197 |
type: bool |
| 198 |
radius_failover_policy: |
| 199 |
choices: |
| 200 |
- Deny access |
| 201 |
- Allow access |
| 202 |
description: |
| 203 |
- Set client access policy in case RADIUS servers aren't available. |
| 204 |
type: str |
| 205 |
radius_load_balancing_policy: |
| 206 |
choices: |
| 207 |
- Strict priority order |
| 208 |
- Round robin |
| 209 |
description: |
| 210 |
- Set load balancing policy when multiple RADIUS servers are specified. |
| 211 |
type: str |
| 212 |
radius_proxy_enabled: |
| 213 |
description: |
| 214 |
- Enable or disable RADIUS Proxy on SSID. |
| 215 |
type: bool |
| 216 |
radius_servers: |
| 217 |
description: |
| 218 |
- List of RADIUS servers. |
| 219 |
elements: dict |
| 220 |
suboptions: |
| 221 |
host: |
| 222 |
description: |
| 223 |
- IP address or hostname of RADIUS server. |
| 224 |
required: true |
| 225 |
type: str |
| 226 |
port: |
| 227 |
description: |
| 228 |
- Port number RADIUS server is listening to. |
| 229 |
type: int |
| 230 |
secret: |
| 231 |
description: |
| 232 |
- RADIUS password. |
| 233 |
- Setting password is not idempotent. |
| 234 |
type: str |
| 235 |
type: list |
| 236 |
splash_guest_sponsor_domains: |
| 237 |
description: |
| 238 |
- List of valid sponsor email domains for sponsored guest portal. |
| 239 |
elements: str |
| 240 |
type: list |
| 241 |
splash_page: |
| 242 |
choices: |
| 243 |
- None |
| 244 |
- Click-through splash page |
| 245 |
- Billing |
| 246 |
- Password-protected with Meraki RADIUS |
| 247 |
- Password-protected with custom RADIUS |
| 248 |
- Password-protected with Active Directory |
| 249 |
- Password-protected with LDAP |
| 250 |
- SMS authentication |
| 251 |
- Systems Manager Sentry |
| 252 |
- Facebook Wi-Fi |
| 253 |
- Google OAuth |
| 254 |
- Sponsored guest |
| 255 |
- Cisco ISE |
| 256 |
description: |
| 257 |
- Set to enable splash page and specify type of splash. |
| 258 |
type: str |
| 259 |
state: |
| 260 |
choices: |
| 261 |
- absent |
| 262 |
- query |
| 263 |
- present |
| 264 |
default: present |
| 265 |
description: |
| 266 |
- Specifies whether SNMP information should be queried or modified. |
| 267 |
type: str |
| 268 |
use_vlan_tagging: |
| 269 |
description: |
| 270 |
- Set whether to use VLAN tagging. |
| 271 |
- Requires C(default_vlan_id) to be set. |
| 272 |
type: bool |
| 273 |
visible: |
| 274 |
description: |
| 275 |
- Enable or disable whether APs should broadcast this SSID. |
| 276 |
type: bool |
| 277 |
vlan_id: |
| 278 |
description: |
| 279 |
- ID number of VLAN on SSID. |
| 280 |
- Requires C(ip_assignment_mode) to be C(ayer 3 roaming with a concentrator) |
| 281 |
or C(VPN). |
| 282 |
type: int |
| 283 |
walled_garden_enabled: |
| 284 |
description: |
| 285 |
- Enable or disable walled garden functionality. |
| 286 |
type: bool |
| 287 |
walled_garden_ranges: |
| 288 |
description: |
| 289 |
- List of walled garden ranges. |
| 290 |
elements: str |
| 291 |
type: list |
| 292 |
wpa_encryption_mode: |
| 293 |
choices: |
| 294 |
- WPA1 and WPA2 |
| 295 |
- WPA2 only |
| 296 |
- WPA3 Transition Mode |
| 297 |
- WPA3 only |
| 298 |
description: |
| 299 |
- Encryption mode within WPA specification. |
| 300 |
type: str |
| 301 |
short_description: Manage wireless SSIDs in the Meraki cloud |
| 302 |
""" |
| 303 |
|
| 304 |
EXAMPLES = r""" |
| 305 |
- name: Enable and name SSID |
| 306 |
meraki_ssid: |
| 307 |
auth_key: abc123 |
| 308 |
state: present |
| 309 |
org_name: YourOrg |
| 310 |
net_name: WiFi |
| 311 |
name: GuestSSID |
| 312 |
enabled: true |
| 313 |
visible: true |
| 314 |
delegate_to: localhost |
| 315 |
- name: Set PSK with invalid encryption mode |
| 316 |
meraki_ssid: |
| 317 |
auth_key: abc123 |
| 318 |
state: present |
| 319 |
org_name: YourOrg |
| 320 |
net_name: WiFi |
| 321 |
name: GuestSSID |
| 322 |
auth_mode: psk |
| 323 |
psk: abc1234 |
| 324 |
encryption_mode: eap |
| 325 |
ignore_errors: true |
| 326 |
delegate_to: localhost |
| 327 |
- name: Configure RADIUS servers |
| 328 |
meraki_ssid: |
| 329 |
auth_key: abc123 |
| 330 |
state: present |
| 331 |
org_name: YourOrg |
| 332 |
net_name: WiFi |
| 333 |
name: GuestSSID |
| 334 |
auth_mode: open-with-radius |
| 335 |
radius_servers: |
| 336 |
- host: 192.0.1.200 |
| 337 |
port: 1234 |
| 338 |
secret: abc98765 |
| 339 |
delegate_to: localhost |
| 340 |
- name: Enable click-through splash page |
| 341 |
meraki_ssid: |
| 342 |
auth_key: abc123 |
| 343 |
state: present |
| 344 |
org_name: YourOrg |
| 345 |
net_name: WiFi |
| 346 |
name: GuestSSID |
| 347 |
splash_page: Click-through splash page |
| 348 |
delegate_to: localhost |
| 349 |
""" |
| 350 |
|
| 351 |
RETURN = r""" |
| 352 |
data: |
| 353 |
description: List of wireless SSIDs. |
| 354 |
returned: success |
| 355 |
type: complex |
| 356 |
contains: |
| 357 |
number: |
| 358 |
description: Zero-based index number for SSIDs. |
| 359 |
returned: success |
| 360 |
type: int |
| 361 |
sample: 0 |
| 362 |
name: |
| 363 |
description: |
| 364 |
- Name of wireless SSID. |
| 365 |
- This value is what is broadcasted. |
| 366 |
returned: success |
| 367 |
type: str |
| 368 |
sample: CorpWireless |
| 369 |
enabled: |
| 370 |
description: Enabled state of wireless network. |
| 371 |
returned: success |
| 372 |
type: bool |
| 373 |
sample: true |
| 374 |
splash_page: |
| 375 |
description: Splash page to show when user authenticates. |
| 376 |
returned: success |
| 377 |
type: str |
| 378 |
sample: Click-through splash page |
| 379 |
ssid_admin_accessible: |
| 380 |
description: Whether SSID is administratively accessible. |
| 381 |
returned: success |
| 382 |
type: bool |
| 383 |
sample: true |
| 384 |
auth_mode: |
| 385 |
description: Authentication method. |
| 386 |
returned: success |
| 387 |
type: str |
| 388 |
sample: psk |
| 389 |
psk: |
| 390 |
description: Secret wireless password. |
| 391 |
returned: success |
| 392 |
type: str |
| 393 |
sample: SecretWiFiPass |
| 394 |
encryption_mode: |
| 395 |
description: Wireless traffic encryption method. |
| 396 |
returned: success |
| 397 |
type: str |
| 398 |
sample: wpa |
| 399 |
wpa_encryption_mode: |
| 400 |
description: Enabled WPA versions. |
| 401 |
returned: success |
| 402 |
type: str |
| 403 |
sample: WPA2 only |
| 404 |
ip_assignment_mode: |
| 405 |
description: Wireless client IP assignment method. |
| 406 |
returned: success |
| 407 |
type: str |
| 408 |
sample: NAT mode |
| 409 |
min_bitrate: |
| 410 |
description: Minimum bitrate a wireless client can connect at. |
| 411 |
returned: success |
| 412 |
type: int |
| 413 |
sample: 11 |
| 414 |
band_selection: |
| 415 |
description: Wireless RF frequency wireless network will be broadcast on. |
| 416 |
returned: success |
| 417 |
type: str |
| 418 |
sample: 5 GHz band only |
| 419 |
per_client_bandwidth_limit_up: |
| 420 |
description: Maximum upload bandwidth a client can use. |
| 421 |
returned: success |
| 422 |
type: int |
| 423 |
sample: 1000 |
| 424 |
per_client_bandwidth_limit_down: |
| 425 |
description: Maximum download bandwidth a client can use. |
| 426 |
returned: success |
| 427 |
type: int |
| 428 |
sample: 0 |
| 429 |
""" |
| 430 |
|
| 431 |
from ansible.module_utils.basic import AnsibleModule, json |
| 432 |
from ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki import ( |
| 433 |
MerakiModule, |
| 434 |
meraki_argument_spec, |
| 435 |
) |
| 436 |
|
| 437 |
|
| 438 |
def get_available_number(data): |
| 439 |
for item in data: |
| 440 |
if "Unconfigured SSID" in item["name"]: |
| 441 |
return item["number"] |
| 442 |
return False |
| 443 |
|
| 444 |
|
| 445 |
def get_ssid_number(name, data): |
| 446 |
for ssid in data: |
| 447 |
if name == ssid["name"]: |
| 448 |
return ssid["number"] |
| 449 |
return False |
| 450 |
|
| 451 |
|
| 452 |
def get_ssids(meraki, net_id): |
| 453 |
path = meraki.construct_path("get_all", net_id=net_id) |
| 454 |
return meraki.request(path, method="GET") |
| 455 |
|
| 456 |
|
| 457 |
def construct_payload(meraki): |
| 458 |
param_map = { |
| 459 |
"name": "name", |
| 460 |
"enabled": "enabled", |
| 461 |
"authMode": "auth_mode", |
| 462 |
"encryptionMode": "encryption_mode", |
| 463 |
"psk": "psk", |
| 464 |
"wpaEncryptionMode": "wpa_encryption_mode", |
| 465 |
"splashPage": "splash_page", |
| 466 |
"radiusServers": "radius_servers", |
| 467 |
"radiusProxyEnabled": "radius_proxy_enabled", |
| 468 |
"radiusCoaEnabled": "radius_coa_enabled", |
| 469 |
"radiusFailoverPolicy": "radius_failover_policy", |
| 470 |
"radiusLoadBalancingPolicy": "radius_load_balancing_policy", |
| 471 |
"radiusAccountingEnabled": "radius_accounting_enabled", |
| 472 |
"radiusAccountingServers": "radius_accounting_servers", |
| 473 |
"ipAssignmentMode": "ip_assignment_mode", |
| 474 |
"useVlanTagging": "use_vlan_tagging", |
| 475 |
"visible": "visible", |
| 476 |
"concentratorNetworkId": "concentrator_network_id", |
| 477 |
"vlanId": "vlan_id", |
| 478 |
"lanIsolationEnabled": "lan_isolation_enabled", |
| 479 |
"availableOnAllAps": "available_on_all_aps", |
| 480 |
"availabilityTags": "ap_availability_tags", |
| 481 |
"defaultVlanId": "default_vlan_id", |
| 482 |
"apTagsAndVlanIds": "ap_tags_vlan_ids", |
| 483 |
"walledGardenEnabled": "walled_garden_enabled", |
| 484 |
"walledGardenRanges": "walled_garden_ranges", |
| 485 |
"minBitrate": "min_bitrate", |
| 486 |
"bandSelection": "band_selection", |
| 487 |
"perClientBandwidthLimitUp": "per_client_bandwidth_limit_up", |
| 488 |
"perClientBandwidthLimitDown": "per_client_bandwidth_limit_down", |
| 489 |
"enterpriseAdminAccess": "enterprise_admin_access", |
| 490 |
"splashGuestSponsorDomains": "splash_guest_sponsor_domains", |
| 491 |
} |
| 492 |
|
| 493 |
payload = dict() |
| 494 |
for k, v in param_map.items(): |
| 495 |
if meraki.params[v] is not None: |
| 496 |
payload[k] = meraki.params[v] |
| 497 |
|
| 498 |
if meraki.params["ap_tags_vlan_ids"] is not None: |
| 499 |
for i in payload["apTagsAndVlanIds"]: |
| 500 |
try: |
| 501 |
i["vlanId"] = i["vlan_id"] |
| 502 |
del i["vlan_id"] |
| 503 |
except KeyError: |
| 504 |
pass |
| 505 |
|
| 506 |
return payload |
| 507 |
|
| 508 |
|
| 509 |
def per_line_to_str(data): |
| 510 |
return data.replace("\n", " ") |
| 511 |
|
| 512 |
|
| 513 |
def main(): |
| 514 |
default_payload = { |
| 515 |
"name": "Unconfigured SSID", |
| 516 |
"auth_mode": "open", |
| 517 |
"splashPage": "None", |
| 518 |
"perClientBandwidthLimitUp": 0, |
| 519 |
"perClientBandwidthLimitDown": 0, |
| 520 |
"ipAssignmentMode": "NAT mode", |
| 521 |
"enabled": False, |
| 522 |
"bandSelection": "Dual band operation", |
| 523 |
"minBitrate": 11, |
| 524 |
} |
| 525 |
|
| 526 |
# define the available arguments/parameters that a user can pass to |
| 527 |
# the module |
| 528 |
radius_arg_spec = dict( |
| 529 |
host=dict(type="str", required=True), |
| 530 |
port=dict(type="int"), |
| 531 |
secret=dict(type="str", no_log=True), |
| 532 |
) |
| 533 |
vlan_arg_spec = dict( |
| 534 |
tags=dict(type="list", elements="str"), |
| 535 |
vlan_id=dict(type="int"), |
| 536 |
) |
| 537 |
|
| 538 |
argument_spec = meraki_argument_spec() |
| 539 |
argument_spec.update( |
| 540 |
state=dict( |
| 541 |
type="str", choices=["absent", "present", "query"], default="present" |
| 542 |
), |
| 543 |
number=dict(type="int", aliases=["ssid_number"]), |
| 544 |
name=dict(type="str"), |
| 545 |
org_name=dict(type="str", aliases=["organization"]), |
| 546 |
org_id=dict(type="str"), |
| 547 |
net_name=dict(type="str"), |
| 548 |
net_id=dict(type="str"), |
| 549 |
enabled=dict(type="bool"), |
| 550 |
auth_mode=dict( |
| 551 |
type="str", |
| 552 |
choices=["open", "psk", "open-with-radius", "8021x-meraki", "8021x-radius"], |
| 553 |
), |
| 554 |
encryption_mode=dict(type="str", choices=["wpa", "eap", "wpa-eap"]), |
| 555 |
psk=dict(type="str", no_log=True), |
| 556 |
wpa_encryption_mode=dict( |
| 557 |
type="str", |
| 558 |
choices=["WPA1 and WPA2", "WPA2 only", "WPA3 Transition Mode", "WPA3 only"], |
| 559 |
), |
| 560 |
splash_page=dict( |
| 561 |
type="str", |
| 562 |
choices=[ |
| 563 |
"None", |
| 564 |
"Click-through splash page", |
| 565 |
"Billing", |
| 566 |
"Password-protected with Meraki RADIUS", |
| 567 |
"Password-protected with custom RADIUS", |
| 568 |
"Password-protected with Active Directory", |
| 569 |
"Password-protected with LDAP", |
| 570 |
"SMS authentication", |
| 571 |
"Systems Manager Sentry", |
| 572 |
"Facebook Wi-Fi", |
| 573 |
"Google OAuth", |
| 574 |
"Sponsored guest", |
| 575 |
"Cisco ISE", |
| 576 |
], |
| 577 |
), |
| 578 |
radius_servers=dict( |
| 579 |
type="list", default=None, elements="dict", options=radius_arg_spec |
| 580 |
), |
| 581 |
radius_proxy_enabled=dict(type="bool"), |
| 582 |
radius_coa_enabled=dict(type="bool"), |
| 583 |
radius_failover_policy=dict( |
| 584 |
type="str", choices=["Deny access", "Allow access"] |
| 585 |
), |
| 586 |
radius_load_balancing_policy=dict( |
| 587 |
type="str", choices=["Strict priority order", "Round robin"] |
| 588 |
), |
| 589 |
radius_accounting_enabled=dict(type="bool"), |
| 590 |
radius_accounting_servers=dict( |
| 591 |
type="list", elements="dict", options=radius_arg_spec |
| 592 |
), |
| 593 |
ip_assignment_mode=dict( |
| 594 |
type="str", |
| 595 |
choices=[ |
| 596 |
"NAT mode", |
| 597 |
"Bridge mode", |
| 598 |
"Layer 3 roaming", |
| 599 |
"Layer 3 roaming with a concentrator", |
| 600 |
"VPN", |
| 601 |
], |
| 602 |
), |
| 603 |
use_vlan_tagging=dict(type="bool"), |
| 604 |
visible=dict(type="bool"), |
| 605 |
lan_isolation_enabled=dict(type="bool"), |
| 606 |
available_on_all_aps=dict(type="bool"), |
| 607 |
ap_availability_tags=dict(type="list", elements="str"), |
| 608 |
concentrator_network_id=dict(type="str"), |
| 609 |
vlan_id=dict(type="int"), |
| 610 |
default_vlan_id=dict(type="int"), |
| 611 |
ap_tags_vlan_ids=dict( |
| 612 |
type="list", default=None, elements="dict", options=vlan_arg_spec |
| 613 |
), |
| 614 |
walled_garden_enabled=dict(type="bool"), |
| 615 |
walled_garden_ranges=dict(type="list", elements="str"), |
| 616 |
min_bitrate=dict( |
| 617 |
type="float", choices=[1, 2, 5.5, 6, 9, 11, 12, 18, 24, 36, 48, 54] |
| 618 |
), |
| 619 |
band_selection=dict( |
| 620 |
type="str", |
| 621 |
choices=[ |
| 622 |
"Dual band operation", |
| 623 |
"5 GHz band only", |
| 624 |
"Dual band operation with Band Steering", |
| 625 |
], |
| 626 |
), |
| 627 |
per_client_bandwidth_limit_up=dict(type="int"), |
| 628 |
per_client_bandwidth_limit_down=dict(type="int"), |
| 629 |
enterprise_admin_access=dict( |
| 630 |
type="str", choices=["access disabled", "access enabled"] |
| 631 |
), |
| 632 |
splash_guest_sponsor_domains=dict(type="list", elements="str"), |
| 633 |
) |
| 634 |
|
| 635 |
# the AnsibleModule object will be our abstraction working with Ansible |
| 636 |
# this includes instantiation, a couple of common attr would be the |
| 637 |
# args/params passed to the execution, as well as if the module |
| 638 |
# supports check mode |
| 639 |
module = AnsibleModule( |
| 640 |
argument_spec=argument_spec, |
| 641 |
supports_check_mode=True, |
| 642 |
) |
| 643 |
meraki = MerakiModule(module, function="ssid") |
| 644 |
meraki.params["follow_redirects"] = "all" |
| 645 |
|
| 646 |
query_urls = {"ssid": "/networks/{net_id}/wireless/ssids"} |
| 647 |
query_url = {"ssid": "/networks/{net_id}/wireless/ssids/{number}"} |
| 648 |
update_url = {"ssid": "/networks/{net_id}/wireless/ssids/"} |
| 649 |
|
| 650 |
meraki.url_catalog["get_all"].update(query_urls) |
| 651 |
meraki.url_catalog["get_one"].update(query_url) |
| 652 |
meraki.url_catalog["update"] = update_url |
| 653 |
|
| 654 |
payload = None |
| 655 |
|
| 656 |
# execute checks for argument completeness |
| 657 |
if meraki.params["psk"]: |
| 658 |
if meraki.params["auth_mode"] != "psk": |
| 659 |
meraki.fail_json(msg="PSK is only allowed when auth_mode is set to psk") |
| 660 |
if meraki.params["encryption_mode"] != "wpa": |
| 661 |
meraki.fail_json(msg="PSK requires encryption_mode be set to wpa") |
| 662 |
if meraki.params["radius_servers"]: |
| 663 |
if meraki.params["auth_mode"] not in ("open-with-radius", "8021x-radius"): |
| 664 |
meraki.fail_json( |
| 665 |
msg="radius_servers requires auth_mode to be open-with-radius or 8021x-radius" |
| 666 |
) |
| 667 |
if meraki.params["radius_accounting_enabled"] is True: |
| 668 |
if meraki.params["auth_mode"] not in ("open-with-radius", "8021x-radius"): |
| 669 |
meraki.fail_json( |
| 670 |
msg="radius_accounting_enabled is only allowed when auth_mode is open-with-radius or 8021x-radius" |
| 671 |
) |
| 672 |
if meraki.params["radius_accounting_servers"] is True: |
| 673 |
if ( |
| 674 |
meraki.params["auth_mode"] not in ("open-with-radius", "8021x-radius") |
| 675 |
or meraki.params["radius_accounting_enabled"] is False |
| 676 |
): |
| 677 |
meraki.fail_json( |
| 678 |
msg="radius_accounting_servers is only allowed when auth_mode is open_with_radius or 8021x-radius and \ |
| 679 |
radius_accounting_enabled is true" |
| 680 |
) |
| 681 |
if meraki.params["use_vlan_tagging"] is True: |
| 682 |
if meraki.params["default_vlan_id"] is None: |
| 683 |
meraki.fail_json( |
| 684 |
msg="default_vlan_id is required when use_vlan_tagging is True" |
| 685 |
) |
| 686 |
if meraki.params["lan_isolation_enabled"] is not None: |
| 687 |
if meraki.params["ip_assignment_mode"] not in ("Bridge mode"): |
| 688 |
meraki.fail_json( |
| 689 |
msg="lan_isolation_enabled is only allowed when ip_assignment_mode is Bridge mode" |
| 690 |
) |
| 691 |
if meraki.params["available_on_all_aps"] is False: |
| 692 |
if not meraki.params["ap_availability_tags"]: |
| 693 |
meraki.fail_json( |
| 694 |
msg="available_on_all_aps is only allowed to be false when ap_availability_tags is defined" |
| 695 |
) |
| 696 |
if meraki.params["ap_availability_tags"]: |
| 697 |
if meraki.params["available_on_all_aps"] is not False: |
| 698 |
meraki.fail_json( |
| 699 |
msg="ap_availability_tags is only allowed when available_on_all_aps is false" |
| 700 |
) |
| 701 |
# manipulate or modify the state as needed (this is going to be the |
| 702 |
# part where your module will do what it needs to do) |
| 703 |
org_id = meraki.params["org_id"] |
| 704 |
net_id = meraki.params["net_id"] |
| 705 |
if org_id is None: |
| 706 |
org_id = meraki.get_org_id(meraki.params["org_name"]) |
| 707 |
if net_id is None: |
| 708 |
nets = meraki.get_nets(org_id=org_id) |
| 709 |
net_id = meraki.get_net_id(org_id, meraki.params["net_name"], data=nets) |
| 710 |
|
| 711 |
if meraki.params["state"] == "query": |
| 712 |
if meraki.params["name"]: |
| 713 |
ssid_id = get_ssid_number(meraki.params["name"], get_ssids(meraki, net_id)) |
| 714 |
path = meraki.construct_path( |
| 715 |
"get_one", net_id=net_id, custom={"number": ssid_id} |
| 716 |
) |
| 717 |
meraki.result["data"] = meraki.request(path, method="GET") |
| 718 |
elif meraki.params["number"] is not None: |
| 719 |
path = meraki.construct_path( |
| 720 |
"get_one", net_id=net_id, custom={"number": meraki.params["number"]} |
| 721 |
) |
| 722 |
meraki.result["data"] = meraki.request(path, method="GET") |
| 723 |
else: |
| 724 |
meraki.result["data"] = get_ssids(meraki, net_id) |
| 725 |
elif meraki.params["state"] == "present": |
| 726 |
payload = construct_payload(meraki) |
| 727 |
ssids = get_ssids(meraki, net_id) |
| 728 |
number = meraki.params["number"] |
| 729 |
if number is None: |
| 730 |
number = get_ssid_number(meraki.params["name"], ssids) |
| 731 |
original = ssids[number] |
| 732 |
if meraki.is_update_required(original, payload, optional_ignore=["secret"]): |
| 733 |
ssid_id = meraki.params["number"] |
| 734 |
if ssid_id is None: # Name should be used to lookup number |
| 735 |
ssid_id = get_ssid_number(meraki.params["name"], ssids) |
| 736 |
if ssid_id is False: |
| 737 |
ssid_id = get_available_number(ssids) |
| 738 |
if ssid_id is False: |
| 739 |
meraki.fail_json( |
| 740 |
msg="No unconfigured SSIDs are available. Specify a number." |
| 741 |
) |
| 742 |
if meraki.check_mode is True: |
| 743 |
original.update(payload) |
| 744 |
meraki.result["data"] = original |
| 745 |
meraki.result["changed"] = True |
| 746 |
meraki.exit_json(**meraki.result) |
| 747 |
path = meraki.construct_path("update", net_id=net_id) + str(ssid_id) |
| 748 |
result = meraki.request(path, "PUT", payload=json.dumps(payload)) |
| 749 |
meraki.result["data"] = result |
| 750 |
meraki.result["changed"] = True |
| 751 |
else: |
| 752 |
meraki.result["data"] = original |
| 753 |
elif meraki.params["state"] == "absent": |
| 754 |
ssids = get_ssids(meraki, net_id) |
| 755 |
ssid_id = meraki.params["number"] |
| 756 |
if ssid_id is None: # Name should be used to lookup number |
| 757 |
ssid_id = get_ssid_number(meraki.params["name"], ssids) |
| 758 |
if ssid_id is False: |
| 759 |
# This will return True as long as there's an unclaimed SSID number! |
| 760 |
ssid_id = get_available_number(ssids) |
| 761 |
# There are no available SSIDs or SSID numbers |
| 762 |
if ssid_id is False: |
| 763 |
meraki.fail_json( |
| 764 |
msg="No SSID found by specified name and no numbers unclaimed." |
| 765 |
) |
| 766 |
meraki.result["changed"] = False |
| 767 |
meraki.result["data"] = {} |
| 768 |
meraki.exit_json(**meraki.result) |
| 769 |
if meraki.check_mode is True: |
| 770 |
meraki.result["data"] = {} |
| 771 |
meraki.result["changed"] = True |
| 772 |
meraki.exit_json(**meraki.result) |
| 773 |
path = meraki.construct_path("update", net_id=net_id) + str(ssid_id) |
| 774 |
payload = default_payload |
| 775 |
payload["name"] = payload["name"] + " " + str(ssid_id + 1) |
| 776 |
result = meraki.request(path, "PUT", payload=json.dumps(payload)) |
| 777 |
meraki.result["data"] = result |
| 778 |
meraki.result["changed"] = True |
| 779 |
|
| 780 |
# in the event of a successful module execution, you will want to |
| 781 |
# simple AnsibleModule.exit_json(), passing the key/value results |
| 782 |
meraki.exit_json(**meraki.result) |
| 783 |
|
| 784 |
|
| 785 |
if __name__ == "__main__": |
| 786 |
main() |