|
46 | 46 |
|
47 | 47 | # Generate all required commands using jinja2 template instead of looping |
48 | 48 | # 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 |
50 | 51 | onyx_config: |
51 | 52 | lines: | |
52 | 53 | {%- set commands = [] -%} |
|
63 | 64 | {%- if interface['iface_mode'] and interface['vlan'] -%} |
64 | 65 | {{ commands.append('interface ' + interface['iface'] + ' switchport mode ' + interface['iface_mode']) }} |
65 | 66 | {%- 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') }} |
67 | 77 | {%- set helper_vlans = [] -%} |
68 | 78 | {%- set vlans = [] -%} |
69 | 79 | {%- 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') }} |
71 | 81 | {%- elif ',' in interface['vlan'] -%} |
72 | 82 | {%- for vlan in interface['vlan'].replace(' ', '').split(',') -%} |
73 | 83 | {{ helper_vlans.append(vlan) }} |
|
85 | 95 | {%- endif -%} |
86 | 96 | {%- endfor -%} |
87 | 97 | {%- 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) }} |
89 | 99 | {%- 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') }} |
91 | 101 | {%- elif interface['iface_mode'] == 'access' -%} |
92 | 102 | {%- if interface['vlan'] | int -%} |
93 | 103 | {{ commands.append('interface ' + interface['iface'] + ' switchport access vlan ' + interface['vlan'] | string) }} |
|
0 commit comments