access: fix parsing of existing switch VLANs

If ansible won’t handle edge cases then we must.
This commit is contained in:
Timotej Lazar 2025-09-18 16:47:39 +02:00
parent 6ade4f2f8a
commit 9ec6241e4a

View file

@ -18,8 +18,9 @@
# Determine VLANs to add and remove from switch. # Determine VLANs to add and remove from switch.
- set_fact: - set_fact:
actual_vlans: "{{ vlans | map(attribute='vid') }}" actual_vlans: "{{ vlans | map(attribute='vid') }}"
switch_vlans: "{{ ansible_net_config | split('\n') | select('match', '^ *vlan (range )?[0-9]') switch_vlans: "{{ ansible_net_config | split('\n')
| map('regex_search', '[0-9,-]+') | join(',') | ansible.netcommon.vlan_expander }}" | select('match', '^ *vlan (range )?[0-9]') | map('regex_search', '[0-9,-]+') | join(',')
| default('0', true) | ansible.netcommon.vlan_expander | reject('eq', 0) }}" # vlan_expander barfs on empty string so add/remove a fake VLAN 0
- set_fact: - set_fact:
add_vlans: "{{ actual_vlans | difference(switch_vlans) }}" add_vlans: "{{ actual_vlans | difference(switch_vlans) }}"