-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathswitch.j2
210 lines (209 loc) · 5.1 KB
/
switch.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
!Configuration Built on {{ now }}
enable
!
configure terminal
!
clock timezone {{ timezone }}
!
hostname {{ hostname }}
!
no ip domain lookup
!
{% if domain_name|length > 0 %}
ip domain name {{ domain_name }}
{% endif %}
!
{% if vtp_domain|length > 0 %}
vtp domain {{ vtp_domain }}
!
{% endif %}
{% if vtp_version|length > 0 %}
vtp version {{ vtp_version }}
!
{% endif %}
vtp mode {{ vtp_mode }}
!
{% if logging_console|length > 0 %}
logging console {{ logging_console }}
{% endif %}
!
{% if logging_buffer_size|length > 0 %}
logging buffered {{ logging_buffer_size }}
!
{% endif %}
username {{ username }} privilege 15 algorithm-type {{ algorithm_type }} secret {{ password }}
{% if enable_password|length > 0 %}
!
enable algorithm-type {{ algorithm_type }} secret {{ enable_password }}
{% endif %}
!
spanning-tree mode {{ stp_mode }}
!
{% if lldp == 'yes' %}
lldp run
{% endif %}
!
{% if ssh_key_size|length > 0 %}
crypto key generate rsa general-keys modulus {{ ssh_key_size }}
!
{% endif %}
{% if ssh_key_size|int >= 1024 and ssh_version == '2' %}
ip ssh version 2
{% else %}
ip ssh version 1.99
{% endif %}
!
{% if http_server == 'no' %}
no ip http server
!
no ip http secure-server
{% endif %}
!
{% if errdisable == 'yes' %}
errdisable recovery cause all
!
errdisable recovery interval {{ errdisable_recovery_interval }}
{% endif %}
!
banner motd $
#################** D I S C L A I M E R **##################
# #
# UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED #
# #
# Restricted to authorized individuals ONLY. #
# #
# You MUST have explicit, authorized permission to #
# access or configure this device. #
# #
# All activities performed on this device are logged, #
# monitored, and recorded. #
# #
# Unauthorized attempts and actions to access, modify #
# or use this system may result in civil and/or criminal #
# penalties. #
# #
# Disconnect IMMEDIATELY if you are not an authorized #
# user. #
# #
############################################################
$
!
interface Vlan 1
no ip address
shutdown
exit
!
{% for vlan in vlans %}
{% if vlan.id|int <= 4094 %}
vlan {{ vlan.id }}
name {{ vlan.name|replace(" ", "_")|truncate(32, True, "") }}
exit
!
{% if vlan.ip_addr|length > 0 %}
interface Vlan {{ vlan.id }}
ip address {{ vlan.ip_addr }} {{ vlan.mask }}
{% if vlan.desc|length > 0 %}
description *** {{ vlan.desc }} ***
{% endif %}
no shutdown
exit
!
{% endif %}
{% else %}
{{ raise("VLAN ID cannot be greater than 4094. Got " ~ vlan.id ~ " instead. Please check 02_vlans.csv file.") }}
{% endif %}
{% endfor %}
{% for portchannel in etherchannels %}
interface port-channel {{ portchannel.id }}
{% if portchannel.type == 'L2' %}
switchport mode {{ portchannel.mode }}
{% endif %}
{% if portchannel.type == 'L2' and portchannel.mode == 'access' and portchannel.access_vlan|length > 0 %}
switchport access vlan {{ portchannel.access_vlan }}
{% endif %}
{% if portchannel.type == 'L2' and portchannel.mode == 'trunk' and portchannel.native_vlan|length > 0 %}
switchport trunk native vlan {{ portchannel.native_vlan }}
{% endif %}
{% if portchannel.type == 'L2' and portchannel.mode == 'trunk' and (portchannel.allowed_vlans != 'all' and portchannel.allowed_vlans|length > 0) %}
switchport trunk allowed vlans {{ portchannel.allowed_vlans }}
{% endif %}
{% if portchannel.type == 'L3' %}
no switchport
ip address {{ portchannel.ip_addr }} {{ portchannel.mask }}
{% endif %}
{% if portchannel.desc|length > 0 %}
description *** {{ portchannel.desc }} ***
{% endif %}
no shutdown
exit
!
{% endfor %}
{% for port in interfaces %}
interface {{ port.name }}
{% if port.mode != 'trunk' and port.mode != 'access' %}
{{ port.mode }}
{% if port.desc|length > 0 %}
description *** {{ port.desc }} ***
{% endif %}
{% endif %}
{% if port.mode == 'access' %}
switchport mode access
{% if port.access_vlan|length > 0 %}
switchport access vlan {{ port.access_vlan }}
{% endif %}
{% if port.voice_vlan|length > 0 %}
switchport voice vlan {{ port.voice_vlan }}
{% endif %}
{% endif %}
{% if port.mode == 'access' and port.portsecurity == 'yes' %}
switchport port-security
switchport port-security mac-address sticky
{% endif %}
{% if port.mode == 'trunk' %}
switchport mode trunk
{% endif %}
{% if port.mode == 'trunk' and port.native_vlan != '' %}
switchport trunk native vlan {{ port.native_vlan }}
{% endif %}
{% if (port.mode == 'trunk' and (port.allowed_vlans != 'all' and port.allowed_vlans|length > 0)) %}
switchport trunk allowed vlans {{ port.allowed_vlans }}
{% endif %}
{% if port.portfast == 'yes' %}
spanning-tree portfast
{% endif %}
{% if port.bpduguard == 'yes' %}
spanning-tree bpduguard enable
{% endif %}
{% if port.description|length > 0 %}
description *** {{ port.description }} ***
{% endif %}
exit
!
{% endfor %}
line console 0
logging synchronous
login local
stopbits 1
exit
!
line vty 0 {{ vty_lines }}
logging synchronous
{% if login_local == 'yes' %}
login local
{% endif %}
exec-timeout {{ timeout }} 0
{% if transport_input|length > 0 %}
transport input {{ transport_input }}
{% else %}
transport input all
{% endif %}
{% if transport_output|length > 0 %}
transport output {{ transport_output }}
{% else %}
transport output all
{% endif %}
exit
!
end
!
! copy running-config startup-config