|
1 | 1 | ---
|
2 |
| -- name: Initial Configuration of MX VLANs for {{ appliance.name }} |
| 2 | +- name: Query Existing MX VLANs |
| 3 | + cisco.meraki.networks_appliance_vlans_info: |
| 4 | + meraki_api_key: "{{ auth_key }}" |
| 5 | + networkId: "{{ network_id }}" |
| 6 | + register: vlan_result |
| 7 | + |
| 8 | +- name: Add discovered VLAN IDs to list |
| 9 | + ansible.builtin.set_fact: |
| 10 | + vlan_ids: >- |
| 11 | + {{ vlan_ids | default([]) + [result.id] }} |
| 12 | + loop: "{{ vlan_result.meraki_response }}" |
| 13 | + loop_control: |
| 14 | + loop_var: result |
| 15 | + when: vlan_result is defined |
| 16 | + |
| 17 | +# |
| 18 | +# First pass configuration throws the following errors when run |
| 19 | +# when vlanId parameter is omitted: |
| 20 | +# Error: Appliance.getNetworkApplianceVlan() missing 1 required positional argument: 'vlanId' |
| 21 | +# |
| 22 | +# When vlanId parameter is present: |
| 23 | +# Error: An error occured when executing operation. |
| 24 | +# The error was: appliance, getNetworkApplianceVlan - 404 Not Found, please wait a minute if the key or org was just newly created. |
| 25 | +# |
| 26 | +# VLANs are provisioned correctly regardless of error as noted above |
| 27 | +# |
| 28 | + |
| 29 | +- name: First Pass Configuration of MX VLANs for {{ appliance.name }} |
3 | 30 | cisco.meraki.networks_appliance_vlans:
|
4 | 31 | meraki_api_key: "{{ auth_key }}"
|
5 | 32 | state: "{{ vlan.state }}"
|
6 | 33 | networkId: "{{ network_id }}"
|
7 | 34 | id: "{{ vlan.id }}"
|
| 35 | + vlanId: "{{ vlan.id }}" |
8 | 36 | name: "{{ vlan.name | default(omit) }}"
|
9 | 37 | subnet: "{{ vlan.subnet | default(omit) }}"
|
10 | 38 | applianceIp: "{{ vlan.appliance_ip | default(omit) }}"
|
11 | 39 | loop: "{{ appliance.vlans }}"
|
12 | 40 | loop_control:
|
13 | 41 | loop_var: vlan
|
| 42 | + when: vlan.id not in vlan_ids and vlan.state == "present" |
14 | 43 |
|
15 | 44 | - name: Second Pass Configuration of MX VLANs for {{ appliance.name }}
|
16 | 45 | cisco.meraki.networks_appliance_vlans:
|
17 | 46 | meraki_api_key: "{{ auth_key }}"
|
18 | 47 | state: "{{ vlan.state }}"
|
19 | 48 | networkId: "{{ network_id }}"
|
20 |
| - id: "{{ vlan.id }}" |
| 49 | + vlanId: "{{ vlan.id }}" |
21 | 50 | name: "{{ vlan.name | default(omit) }}"
|
22 | 51 | reservedIpRanges: "{{ vlan.reserved_ip_range | default(omit) }}"
|
23 | 52 | fixedIpAssignments: "{{ vlan.fixed_ip_assignments | default(omit) }}"
|
|
29 | 58 | ((vlan.reserved_ip_range is defined) or
|
30 | 59 | (vlan.fixed_ip_assignments is defined) or
|
31 | 60 | (vlan.dns_nameservers is defined)) and
|
| 61 | + vlan.id not in vlan_ids and |
32 | 62 | vlan.state == "present"
|
| 63 | +
|
| 64 | +- name: Update Configuration of Existing MX VLANs for {{ appliance.name }} |
| 65 | + cisco.meraki.networks_appliance_vlans: |
| 66 | + meraki_api_key: "{{ auth_key }}" |
| 67 | + state: "{{ vlan.state }}" |
| 68 | + networkId: "{{ network_id }}" |
| 69 | + vlanId: "{{ vlan.id }}" |
| 70 | + name: "{{ vlan.name | default(omit) }}" |
| 71 | + subnet: "{{ vlan.subnet | default(omit) }}" |
| 72 | + applianceIp: "{{ vlan.appliance_ip | default(omit) }}" |
| 73 | + reservedIpRanges: "{{ vlan.reserved_ip_range | default(omit) }}" |
| 74 | + fixedIpAssignments: "{{ vlan.fixed_ip_assignments | default(omit) }}" |
| 75 | + dnsNameservers: "{{ vlan.dns_nameservers | default(omit) }}" |
| 76 | + loop: "{{ appliance.vlans }}" |
| 77 | + loop_control: |
| 78 | + loop_var: vlan |
| 79 | + when: vlan.id in vlan_ids and vlan.state == "present" |
0 commit comments