From 9ec6241e4a5e77c715b49a67329800202a5c2747 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 18 Sep 2025 16:47:39 +0200 Subject: [PATCH] access: fix parsing of existing switch VLANs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If ansible won’t handle edge cases then we must. --- roles/access/tasks/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/access/tasks/main.yml b/roles/access/tasks/main.yml index eee6521..069784c 100644 --- a/roles/access/tasks/main.yml +++ b/roles/access/tasks/main.yml @@ -18,8 +18,9 @@ # Determine VLANs to add and remove from switch. - set_fact: actual_vlans: "{{ vlans | map(attribute='vid') }}" - switch_vlans: "{{ ansible_net_config | split('\n') | select('match', '^ *vlan (range )?[0-9]') - | map('regex_search', '[0-9,-]+') | join(',') | ansible.netcommon.vlan_expander }}" + switch_vlans: "{{ ansible_net_config | split('\n') + | 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: add_vlans: "{{ actual_vlans | difference(switch_vlans) }}"