| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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.organizations_appliance_vpn_third_party_vpnpeers |
| 22 |
removed_in: 3.0.0 |
| 23 |
why: Updated modules released with increased functionality |
| 24 |
description: |
| 25 |
- Create, edit, query, or delete third party VPN peers in a Meraki environment. |
| 26 |
extends_documentation_fragment: cisco.meraki.meraki |
| 27 |
module: meraki_mx_third_party_vpn_peers |
| 28 |
options: |
| 29 |
peers: |
| 30 |
description: |
| 31 |
- The list of VPN peers. |
| 32 |
elements: dict |
| 33 |
suboptions: |
| 34 |
ike_version: |
| 35 |
choices: |
| 36 |
- '1' |
| 37 |
- '2' |
| 38 |
default: '1' |
| 39 |
description: |
| 40 |
- The IKE version to be used for the IPsec VPN peer configuration. |
| 41 |
type: str |
| 42 |
ipsec_policies: |
| 43 |
description: |
| 44 |
- Custom IPSec policies for the VPN peer. If not included and a preset has |
| 45 |
not been chosen, the default preset for IPSec policies will be used. |
| 46 |
suboptions: |
| 47 |
child_auth_algo: |
| 48 |
choices: |
| 49 |
- sha256 |
| 50 |
- sha1 |
| 51 |
- md5 |
| 52 |
description: |
| 53 |
- This is the authentication algorithms to be used in Phase 2. |
| 54 |
elements: str |
| 55 |
type: list |
| 56 |
child_cipher_algo: |
| 57 |
choices: |
| 58 |
- aes256 |
| 59 |
- aes192 |
| 60 |
- aes128 |
| 61 |
- tripledes |
| 62 |
- des |
| 63 |
- 'null' |
| 64 |
description: |
| 65 |
- This is the cipher algorithms to be used in Phase 2. |
| 66 |
elements: str |
| 67 |
type: list |
| 68 |
child_lifetime: |
| 69 |
description: |
| 70 |
- The lifetime of the Phase 2 SA in seconds. |
| 71 |
type: int |
| 72 |
child_pfs_group: |
| 73 |
choices: |
| 74 |
- disabled |
| 75 |
- group14 |
| 76 |
- group5 |
| 77 |
- group2 |
| 78 |
- group1 |
| 79 |
description: |
| 80 |
- This is the Diffie-Hellman group to be used for Perfect Forward Secrecy |
| 81 |
in Phase 2. |
| 82 |
elements: str |
| 83 |
type: list |
| 84 |
ike_auth_algo: |
| 85 |
choices: |
| 86 |
- sha256 |
| 87 |
- sha1 |
| 88 |
- md5 |
| 89 |
description: |
| 90 |
- This is the authentication algorithm to be used in Phase 1. |
| 91 |
elements: str |
| 92 |
type: list |
| 93 |
ike_cipher_algo: |
| 94 |
choices: |
| 95 |
- aes256 |
| 96 |
- aes192 |
| 97 |
- aes128 |
| 98 |
- tripledes |
| 99 |
- des |
| 100 |
description: |
| 101 |
- This is the cipher algorithm to be used in Phase 1. |
| 102 |
elements: str |
| 103 |
type: list |
| 104 |
ike_diffie_hellman_group: |
| 105 |
choices: |
| 106 |
- group14 |
| 107 |
- group5 |
| 108 |
- group2 |
| 109 |
- group1 |
| 110 |
description: |
| 111 |
- This is the Diffie-Hellman group to be used in Phase 1. |
| 112 |
elements: str |
| 113 |
type: list |
| 114 |
ike_lifetime: |
| 115 |
description: |
| 116 |
- The lifetime of the Phase 1 SA in seconds. |
| 117 |
type: int |
| 118 |
ike_prf_algo: |
| 119 |
choices: |
| 120 |
- prfsha256 |
| 121 |
- prfsha1 |
| 122 |
- prfmd5 |
| 123 |
- default |
| 124 |
description: |
| 125 |
- This is the pseudo-random function to be used in IKE_SA. |
| 126 |
elements: str |
| 127 |
type: list |
| 128 |
type: dict |
| 129 |
ipsec_policies_preset: |
| 130 |
choices: |
| 131 |
- default |
| 132 |
- aws |
| 133 |
- azure |
| 134 |
description: |
| 135 |
- Specifies IPsec preset values. If this is provided, the 'ipsecPolicies' |
| 136 |
parameter is ignored. |
| 137 |
type: str |
| 138 |
name: |
| 139 |
description: |
| 140 |
- The name of the VPN peer. |
| 141 |
- Required when state is present. |
| 142 |
type: str |
| 143 |
network_tags: |
| 144 |
description: |
| 145 |
- A list of network tags that will connect with this peer. If not included, |
| 146 |
the default is ['all']. |
| 147 |
elements: str |
| 148 |
type: list |
| 149 |
private_subnets: |
| 150 |
description: |
| 151 |
- The list of the private subnets of the VPN peer. |
| 152 |
- Required when state is present. |
| 153 |
elements: str |
| 154 |
type: list |
| 155 |
public_ip: |
| 156 |
description: |
| 157 |
- The public IP of the VPN peer. |
| 158 |
- Required when state is present. |
| 159 |
type: str |
| 160 |
remote_id: |
| 161 |
description: |
| 162 |
- The remote ID is used to identify the connecting VPN peer. This can either |
| 163 |
be a valid IPv4 Address, FQDN or User FQDN. |
| 164 |
type: str |
| 165 |
secret: |
| 166 |
description: |
| 167 |
- The shared secret with the VPN peer. |
| 168 |
- Required when state is present. |
| 169 |
type: str |
| 170 |
type: list |
| 171 |
state: |
| 172 |
choices: |
| 173 |
- absent |
| 174 |
- present |
| 175 |
- query |
| 176 |
default: query |
| 177 |
description: |
| 178 |
- Specifies whether object should be queried, created/modified, or removed. |
| 179 |
type: str |
| 180 |
short_description: Manage third party (IPSec) VPN peers for MX devices |
| 181 |
""" |
| 182 |
|
| 183 |
EXAMPLES = r""" |
| 184 |
- name: Query all VPN peers |
| 185 |
meraki_mx_third_party_vpn_peers: |
| 186 |
auth_key: abc123 |
| 187 |
state: query |
| 188 |
org_name: orgName |
| 189 |
- name: Create VPN peer with an IPsec policy |
| 190 |
meraki_mx_third_party_vpn_peers: |
| 191 |
auth_key: abc123 |
| 192 |
state: present |
| 193 |
org_name: orgName |
| 194 |
peers: |
| 195 |
- name: Test peer |
| 196 |
public_ip: 198.51.100.1 |
| 197 |
secret: s3cret |
| 198 |
private_subnets: |
| 199 |
- 192.0.2.0/24 |
| 200 |
ike_version: '2' |
| 201 |
network_tags: |
| 202 |
- none |
| 203 |
remote_id: 192.0.2.0 |
| 204 |
ipsec_policies: |
| 205 |
child_lifetime: 600 |
| 206 |
ike_lifetime: 600 |
| 207 |
child_auth_algo: |
| 208 |
- md5 |
| 209 |
child_cipher_algo: |
| 210 |
- tripledes |
| 211 |
- aes192 |
| 212 |
child_pfs_group: |
| 213 |
- disabled |
| 214 |
ike_auth_algo: |
| 215 |
- sha256 |
| 216 |
ike_cipher_algo: |
| 217 |
- tripledes |
| 218 |
ike_diffie_hellman_group: |
| 219 |
- group2 |
| 220 |
ike_prf_algo: |
| 221 |
- prfmd5 |
| 222 |
""" |
| 223 |
|
| 224 |
RETURN = r""" |
| 225 |
response: |
| 226 |
description: Information about the organization which was created or modified |
| 227 |
returned: success |
| 228 |
type: complex |
| 229 |
contains: |
| 230 |
appliance_ip: |
| 231 |
description: IP address of Meraki appliance in the VLAN |
| 232 |
returned: success |
| 233 |
type: str |
| 234 |
sample: 192.0.1.1 |
| 235 |
dnsnamservers: |
| 236 |
description: IP address or Meraki defined DNS servers which VLAN should use by default |
| 237 |
returned: success |
| 238 |
type: str |
| 239 |
sample: upstream_dns |
| 240 |
peers: |
| 241 |
description: The list of VPN peers. |
| 242 |
returned: success |
| 243 |
type: complex |
| 244 |
contains: |
| 245 |
ike_version: |
| 246 |
description: The IKE version to be used for the IPsec VPN peer configuration. |
| 247 |
returned: success |
| 248 |
type: str |
| 249 |
sample: "1" |
| 250 |
ipsec_policies_preset: |
| 251 |
description: Preconfigured IPsec settings. |
| 252 |
returned: success |
| 253 |
type: str |
| 254 |
sample: "aws" |
| 255 |
name: |
| 256 |
description: The name of the VPN peer. |
| 257 |
returned: success |
| 258 |
type: str |
| 259 |
sample: "MyVPNPeer" |
| 260 |
public_ip: |
| 261 |
description: The public IP of the VPN peer. |
| 262 |
returned: success |
| 263 |
type: str |
| 264 |
sample: "198.51.100.1" |
| 265 |
remote_id: |
| 266 |
description: "The remote ID is used to identify the connecting VPN peer." |
| 267 |
returned: success |
| 268 |
type: str |
| 269 |
sample: "s3cret" |
| 270 |
network_tags: |
| 271 |
description: A list of network tags that will connect with this peer. |
| 272 |
returned: success |
| 273 |
type: list |
| 274 |
sample: ["all"] |
| 275 |
private_subnets: |
| 276 |
description: The list of the private subnets of the VPN peer. |
| 277 |
returned: success |
| 278 |
type: list |
| 279 |
sample: ["192.0.2.0/24"] |
| 280 |
ipsec_policies: |
| 281 |
description: Custom IPSec policies for the VPN peer. |
| 282 |
returned: success |
| 283 |
type: complex |
| 284 |
contains: |
| 285 |
child_lifetime: |
| 286 |
description: The lifetime of the Phase 2 SA in seconds. |
| 287 |
returned: success |
| 288 |
type: str |
| 289 |
sample: "60" |
| 290 |
ike_lifetime: |
| 291 |
description: The lifetime of the Phase 1 SA in seconds. |
| 292 |
returned: success |
| 293 |
type: str |
| 294 |
sample: "60" |
| 295 |
child_auth_algo: |
| 296 |
description: This is the authentication algorithms to be used in Phase 2. |
| 297 |
returned: success |
| 298 |
type: list |
| 299 |
sample: ["sha1"] |
| 300 |
child_cipher_algo: |
| 301 |
description: This is the cipher algorithms to be used in Phase 2. |
| 302 |
returned: success |
| 303 |
type: list |
| 304 |
sample: ["aes192"] |
| 305 |
child_pfs_group: |
| 306 |
description: This is the Diffie-Hellman group to be used for Perfect Forward Secrecy in Phase 2. |
| 307 |
returned: success |
| 308 |
type: list |
| 309 |
sample: ["group14"] |
| 310 |
ike_auth_algo: |
| 311 |
description: This is the authentication algorithm to be used in Phase 1. |
| 312 |
returned: success |
| 313 |
type: list |
| 314 |
sample: ["sha1"] |
| 315 |
ike_cipher_algo: |
| 316 |
description: This is the cipher algorithm to be used in Phase 1. |
| 317 |
returned: success |
| 318 |
type: list |
| 319 |
sample: ["aes128"] |
| 320 |
ike_diffie_hellman_group: |
| 321 |
description: This is the Diffie-Hellman group to be used in Phase 1. |
| 322 |
returned: success |
| 323 |
type: list |
| 324 |
sample: ["group14"] |
| 325 |
ike_prf_algo: |
| 326 |
description: This is the pseudo-random function to be used in IKE_SA. |
| 327 |
returned: success |
| 328 |
type: list |
| 329 |
sample: ["prfmd5"] |
| 330 |
""" |
| 331 |
|
| 332 |
from ansible.module_utils.basic import AnsibleModule |
| 333 |
from ansible_collections.cisco.meraki.plugins.module_utils.network.meraki.meraki import ( |
| 334 |
MerakiModule, |
| 335 |
meraki_argument_spec, |
| 336 |
) |
| 337 |
import json |
| 338 |
|
| 339 |
|
| 340 |
def validate_payload(meraki): |
| 341 |
for peer in meraki.params["peers"]: |
| 342 |
if peer["name"] is None: |
| 343 |
meraki.fail_json(msg="Peer name must be specified") |
| 344 |
elif peer["public_ip"] is None: |
| 345 |
meraki.fail_json(msg="Peer public IP must be specified") |
| 346 |
elif peer["secret"] is None: |
| 347 |
meraki.fail_json(msg="Peer secret must be specified") |
| 348 |
elif peer["private_subnets"] is None: |
| 349 |
meraki.fail_json(msg="Peer private subnets must be specified") |
| 350 |
|
| 351 |
|
| 352 |
def construct_payload(meraki): |
| 353 |
validate_payload(meraki) |
| 354 |
peer_list = [] |
| 355 |
for peer in meraki.params["peers"]: |
| 356 |
current_peer = dict() |
| 357 |
current_peer["name"] = peer["name"] |
| 358 |
current_peer["publicIp"] = peer["public_ip"] |
| 359 |
current_peer["secret"] = peer["secret"] |
| 360 |
current_peer["privateSubnets"] = peer["private_subnets"] |
| 361 |
if peer["ike_version"] is not None: |
| 362 |
current_peer["ikeVersion"] = peer["ike_version"] |
| 363 |
if peer["ipsec_policies_preset"] is not None: |
| 364 |
current_peer["ipsecPoliciesPreset"] = peer["ipsec_policies_preset"] |
| 365 |
if peer["remote_id"] is not None: |
| 366 |
current_peer["remoteId"] = peer["remote_id"] |
| 367 |
if peer["network_tags"] is not None: |
| 368 |
current_peer["networkTags"] = peer["network_tags"] |
| 369 |
if peer["ipsec_policies"] is not None: |
| 370 |
current_peer["ipsecPolicies"] = dict() |
| 371 |
if peer["ipsec_policies"]["child_lifetime"] is not None: |
| 372 |
current_peer["ipsecPolicies"]["childLifetime"] = peer["ipsec_policies"][ |
| 373 |
"child_lifetime" |
| 374 |
] |
| 375 |
if peer["ipsec_policies"]["ike_lifetime"] is not None: |
| 376 |
current_peer["ipsecPolicies"]["ikeLifetime"] = peer["ipsec_policies"][ |
| 377 |
"ike_lifetime" |
| 378 |
] |
| 379 |
if peer["ipsec_policies"]["child_auth_algo"] is not None: |
| 380 |
current_peer["ipsecPolicies"]["childAuthAlgo"] = peer["ipsec_policies"][ |
| 381 |
"child_auth_algo" |
| 382 |
] |
| 383 |
if peer["ipsec_policies"]["child_cipher_algo"] is not None: |
| 384 |
current_peer["ipsecPolicies"]["childCipherAlgo"] = peer[ |
| 385 |
"ipsec_policies" |
| 386 |
]["child_cipher_algo"] |
| 387 |
if peer["ipsec_policies"]["child_pfs_group"] is not None: |
| 388 |
current_peer["ipsecPolicies"]["childPfsGroup"] = peer["ipsec_policies"][ |
| 389 |
"child_pfs_group" |
| 390 |
] |
| 391 |
if peer["ipsec_policies"]["ike_auth_algo"] is not None: |
| 392 |
current_peer["ipsecPolicies"]["ikeAuthAlgo"] = peer["ipsec_policies"][ |
| 393 |
"ike_auth_algo" |
| 394 |
] |
| 395 |
if peer["ipsec_policies"]["ike_cipher_algo"] is not None: |
| 396 |
current_peer["ipsecPolicies"]["ikeCipherAlgo"] = peer["ipsec_policies"][ |
| 397 |
"ike_cipher_algo" |
| 398 |
] |
| 399 |
if peer["ipsec_policies"]["ike_diffie_hellman_group"] is not None: |
| 400 |
current_peer["ipsecPolicies"]["ikeDiffieHellmanGroup"] = peer[ |
| 401 |
"ipsec_policies" |
| 402 |
]["ike_diffie_hellman_group"] |
| 403 |
if peer["ipsec_policies"]["ike_prf_algo"] is not None: |
| 404 |
current_peer["ipsecPolicies"]["ikePrfAlgo"] = peer["ipsec_policies"][ |
| 405 |
"ike_prf_algo" |
| 406 |
] |
| 407 |
|
| 408 |
peer_list.append(current_peer) |
| 409 |
payload = {"peers": peer_list} |
| 410 |
return payload |
| 411 |
|
| 412 |
|
| 413 |
def main(): |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
ipsec_policies_arg_spec = dict( |
| 418 |
child_lifetime=dict(type="int", default=None), |
| 419 |
ike_lifetime=dict(type="int", default=None), |
| 420 |
child_auth_algo=dict( |
| 421 |
type="list", elements="str", default=None, choices=["sha256", "sha1", "md5"] |
| 422 |
), |
| 423 |
child_cipher_algo=dict( |
| 424 |
type="list", |
| 425 |
elements="str", |
| 426 |
default=None, |
| 427 |
choices=["aes256", "aes192", "aes128", "tripledes", "des", "null"], |
| 428 |
), |
| 429 |
child_pfs_group=dict( |
| 430 |
type="list", |
| 431 |
elements="str", |
| 432 |
default=None, |
| 433 |
choices=["disabled", "group14", "group5", "group2", "group1"], |
| 434 |
), |
| 435 |
ike_auth_algo=dict( |
| 436 |
type="list", elements="str", default=None, choices=["sha256", "sha1", "md5"] |
| 437 |
), |
| 438 |
ike_cipher_algo=dict( |
| 439 |
type="list", |
| 440 |
elements="str", |
| 441 |
default=None, |
| 442 |
choices=["aes256", "aes192", "aes128", "tripledes", "des"], |
| 443 |
), |
| 444 |
ike_diffie_hellman_group=dict( |
| 445 |
type="list", |
| 446 |
elements="str", |
| 447 |
default=None, |
| 448 |
choices=["group14", "group5", "group2", "group1"], |
| 449 |
), |
| 450 |
ike_prf_algo=dict( |
| 451 |
type="list", |
| 452 |
elements="str", |
| 453 |
default=None, |
| 454 |
choices=["prfsha256", "prfsha1", "prfmd5", "default"], |
| 455 |
), |
| 456 |
) |
| 457 |
|
| 458 |
peers_arg_spec = dict( |
| 459 |
name=dict(type="str"), |
| 460 |
public_ip=dict(type="str"), |
| 461 |
secret=dict(type="str", no_log=True), |
| 462 |
private_subnets=dict(type="list", elements="str"), |
| 463 |
ike_version=dict(type="str", choices=["1", "2"], default="1"), |
| 464 |
ipsec_policies_preset=dict( |
| 465 |
type="str", choices=["default", "aws", "azure"], default=None |
| 466 |
), |
| 467 |
remote_id=dict(type="str", default=None), |
| 468 |
network_tags=dict(type="list", elements="str", default=None), |
| 469 |
ipsec_policies=dict(type="dict", options=ipsec_policies_arg_spec, default=None), |
| 470 |
) |
| 471 |
|
| 472 |
argument_spec = meraki_argument_spec() |
| 473 |
argument_spec.update( |
| 474 |
state=dict(type="str", choices=["absent", "present", "query"], default="query"), |
| 475 |
peers=dict(type="list", elements="dict", options=peers_arg_spec), |
| 476 |
) |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
module = AnsibleModule( |
| 483 |
argument_spec=argument_spec, |
| 484 |
supports_check_mode=True, |
| 485 |
) |
| 486 |
meraki = MerakiModule(module, function="third_party_vpn_peer") |
| 487 |
|
| 488 |
meraki.params["follow_redirects"] = "all" |
| 489 |
|
| 490 |
query_urls = { |
| 491 |
"third_party_vpn_peer": "/organizations/{org_id}/appliance/vpn/thirdPartyVPNPeers" |
| 492 |
} |
| 493 |
update_url = { |
| 494 |
"third_party_vpn_peer": "/organizations/{org_id}/appliance/vpn/thirdPartyVPNPeers" |
| 495 |
} |
| 496 |
|
| 497 |
meraki.url_catalog["get_all"].update(query_urls) |
| 498 |
meraki.url_catalog["update"] = update_url |
| 499 |
|
| 500 |
payload = None |
| 501 |
if meraki.params["org_id"] is None and meraki.params["org_name"] is None: |
| 502 |
meraki.fail_json(msg="Organization must be specified via org_name or org_id") |
| 503 |
|
| 504 |
org_id = meraki.params["org_id"] |
| 505 |
if org_id is None: |
| 506 |
org_id = meraki.get_org_id(meraki.params["org_name"]) |
| 507 |
|
| 508 |
if meraki.params["state"] == "query": |
| 509 |
path = meraki.construct_path("get_all", org_id=org_id) |
| 510 |
response = meraki.request(path, "GET") |
| 511 |
meraki.result["data"] = response |
| 512 |
elif meraki.params["state"] == "present": |
| 513 |
payload = construct_payload(meraki) |
| 514 |
have = meraki.request(meraki.construct_path("get_all", org_id=org_id), "GET") |
| 515 |
|
| 516 |
if meraki.is_update_required(have, payload): |
| 517 |
meraki.generate_diff(have, payload) |
| 518 |
path = meraki.construct_path("update", org_id=org_id) |
| 519 |
if meraki.module.check_mode is False: |
| 520 |
response = meraki.request(path, "PUT", payload=json.dumps(payload)) |
| 521 |
meraki.result["data"] = response |
| 522 |
else: |
| 523 |
meraki.result["data"] = payload |
| 524 |
meraki.result["changed"] = True |
| 525 |
meraki.exit_json(**meraki.result) |
| 526 |
meraki.result["data"] = have |
| 527 |
elif meraki.params["state"] == "absent": |
| 528 |
return |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
meraki.exit_json(**meraki.result) |
| 533 |
|
| 534 |
|
| 535 |
if __name__ == "__main__": |
| 536 |
main() |