Skip to content

Commit 9b617c6

Browse files
vkhitrinmnietoji
authored andcommitted
switches_config: Add Native VLAN Option
Allow switches to configure native VLAN as part of trunk port. Change-Id: I0bff4207e5e5a280db17ad8bffcd0a3059807754 (cherry picked from commit 45cf1c3)
1 parent f014776 commit 9b617c6

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

roles/configuration/switches_config/tasks/ios_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
{{ access_vlan }}{% else %}{{ omit }}{% endif %}"
9494
trunk_vlans: "{%- if item.iface_mode == 'trunk' -%}
9595
{{ trunk_vlans_list }}{% else %}{{ omit }}{% endif %}"
96+
native_vlan: "{%- if item.iface_mode == 'trunk' and 'native_vlan' in item -%}
97+
{{ item.native_vlan | int }}{% else %}{{ omit }}{% endif %}"
9698
state: present
9799
loop: "{{ switch_vars.interfaces }}"
98100

roles/configuration/switches_config/tasks/junos_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
{{ access_vlan }}{% else %}{{ omit }}{% endif %}"
7070
trunk_vlans: "{%- if item.iface_mode == 'trunk' -%}
7171
{{ trunk_vlans_list }}{% else %}{{ omit }}{% endif %}"
72+
native_vlan: "{%- if item.iface_mode == 'trunk' and 'native_vlan' in item -%}
73+
{{ item.native_vlan | int }}{% else %}{{ omit }}{% endif %}"
7274
unit: 0
7375
state: present
7476
loop: "{{ switch_vars.interfaces }}"

roles/configuration/switches_config/tasks/onyx_config.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
4747
# Generate all required commands using jinja2 template instead of looping
4848
# If we loop, unnecessary SSH connections will run which will increase execution time significantly
49-
- name: Configure interfaces - description, mode (access/trunk), vlans
49+
# If using `hybrid` mode, please exclude the native VLAN from trunk list
50+
- name: Configure interfaces - description, mode (access/trunk/hybrid), vlans
5051
onyx_config:
5152
lines: |
5253
{%- set commands = [] -%}
@@ -63,11 +64,20 @@
6364
{%- if interface['iface_mode'] and interface['vlan'] -%}
6465
{{ commands.append('interface ' + interface['iface'] + ' switchport mode ' + interface['iface_mode']) }}
6566
{%- if interface['iface_mode'] == 'trunk' -%}
66-
{{ commands.append('interface ' + interface['iface'] + ' switchport trunk allowed-vlan none') }}
67+
{%- if 'native_vlan' in interface -%}
68+
{%- set mode = 'hybrid' -%}
69+
{%- set native_commands = ['interface ' + interface['iface'] + ' switchport mode hybrid', 'interface ' + interface['iface'] + ' switchport access vlan ' + interface['native_vlan'] | string] -%}
70+
{%- for command in native_commands -%}
71+
{{ commands.append(command) }}
72+
{%- endfor -%}
73+
{%- else -%}
74+
{%- set mode = 'trunk' -%}
75+
{%- endif -%}
76+
{{ commands.append('interface ' + interface['iface'] + ' switchport ' + mode + ' allowed-vlan none') }}
6777
{%- set helper_vlans = [] -%}
6878
{%- set vlans = [] -%}
6979
{%- if 'all' in interface['vlan'] -%}
70-
{{ commands.append('interface ' + interface['iface'] + ' switchport trunk allowed-vlan all') }}
80+
{{ commands.append('interface ' + interface['iface'] + ' switchport' + mode + 'allowed-vlan all') }}
7181
{%- elif ',' in interface['vlan'] -%}
7282
{%- for vlan in interface['vlan'].replace(' ', '').split(',') -%}
7383
{{ helper_vlans.append(vlan) }}
@@ -85,9 +95,9 @@
8595
{%- endif -%}
8696
{%- endfor -%}
8797
{%- for vlan in vlans | unique -%}
88-
{{ commands.append('interface ' + interface['iface'] + ' switchport trunk allowed-vlan add ' + vlan | string) }}
98+
{{ commands.append('interface ' + interface['iface'] + ' switchport ' + mode + ' allowed-vlan add ' + vlan | string) }}
8999
{%- endfor -%}
90-
{{ commands.append('interface ' + interface['iface'] + ' switchport trunk allowed-vlan remove 1') }}
100+
{{ commands.append('interface ' + interface['iface'] + ' switchport ' + mode + ' allowed-vlan remove 1') }}
91101
{%- elif interface['iface_mode'] == 'access' -%}
92102
{%- if interface['vlan'] | int -%}
93103
{{ commands.append('interface ' + interface['iface'] + ' switchport access vlan ' + interface['vlan'] | string) }}

0 commit comments

Comments
 (0)