forked from zentralwerk/network
108 lines
2.6 KiB
Plaintext
108 lines
2.6 KiB
Plaintext
{# https://www.crc.id.au/real-console-on-linksys-srw2024-switch/ #}
|
|
{%- import_yaml "netmasks.yaml" as netmasks -%}
|
|
#!/usr/bin/expect -f
|
|
|
|
spawn telnet {{ pillar['hosts-inet']['mgmt'][hostname] }}
|
|
expect "Password:"
|
|
send "admin\t{{ switch['password'] }}\r"
|
|
|
|
# ^z
|
|
send "\x1A"
|
|
expect ">"
|
|
send "lcli\r"
|
|
|
|
expect "User Name:"
|
|
send "admin\r"
|
|
expect "Password:"
|
|
send "{{ switch['password'] }}\r"
|
|
|
|
expect "# "
|
|
send "configure\r"
|
|
expect "(config)# "
|
|
send "hostname {{ hostname }}\r"
|
|
expect "(config)# "
|
|
send "management vlan 4094\r"
|
|
expect "(config)# "
|
|
send "vlan database\r"
|
|
expect "(config-vlan)# "
|
|
{%- for name, vlan in pillar['vlans'].items() %}
|
|
{%- if name != 'mgmt' %}
|
|
send "no vlan {{ vlan }}\r"
|
|
{%- endif %}
|
|
send "vlan {{ vlan }}\r"
|
|
expect "(config-vlan)#"
|
|
{%- endfor %}
|
|
send "exit\r"
|
|
expect "(config)#"
|
|
{%- for name, vlan in pillar['vlans'].items() %}
|
|
send "interface vlan {{ vlan }}\r"
|
|
expect "(config-if)#"
|
|
send "name {{ name }}\r"
|
|
expect "(config-if)#"
|
|
send "exit\r"
|
|
expect "(config)#"
|
|
{%- endfor %}
|
|
|
|
{%- for name, conf in switch['ports'].items() %}
|
|
|
|
{%- if conf['mode'] == 'trunk' %}
|
|
{%- for port in conf['ports'] %}
|
|
send "interface ethernet {{ port }}\r"
|
|
expect "(config-if)#"
|
|
send "no channel-group\r"
|
|
expect "(config-if)#"
|
|
send "switchport mode trunk\r"
|
|
expect "(config-if)#"
|
|
{%- set vlan_ids = [] %}
|
|
{%- for name in conf['vlans'] %}
|
|
{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
send "switchport trunk allowed vlan add {{ ','.join(vlan_ids) }}\r"
|
|
expect "(config-if)#"
|
|
send "exit\r"
|
|
expect "(config)#"
|
|
{%- endfor %}
|
|
|
|
{%- elif conf['mode'] == 'bond' %}
|
|
send "interface range ethernet {{ ','.join(conf['ports']) }}\r"
|
|
expect "(config-if)#"
|
|
send "switchport trunk allowed vlan remove all\r"
|
|
expect "(config-if)#"
|
|
send "channel-group {{ conf['group'] }} mode auto\r"
|
|
expect "(config-if)#"
|
|
send "interface port-channel {{ conf['group'] }}\r"
|
|
expect "(config-if)#"
|
|
send "exit\r"
|
|
|
|
send "interface port-channel {{ conf['group'] }}\r"
|
|
expect "(config-if)#"
|
|
send "switchport mode trunk\r"
|
|
expect "(config-if)#"
|
|
{%- set vlan_ids = [] %}
|
|
{%- for name in conf['vlans'] %}
|
|
{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
send "switchport trunk allowed vlan add {{ ','.join(vlan_ids) }}\r"
|
|
expect "(config-if)#"
|
|
|
|
send "exit\r"
|
|
expect "(config)#"
|
|
|
|
{%- elif conf['mode'] == 'access' %}
|
|
{%- for port in conf['ports'] %}
|
|
send "interface ethernet {{ port }}\r"
|
|
expect "(config-if)#"
|
|
send "no channel-group\r"
|
|
expect "(config-if)#"
|
|
send "switchport mode access\r"
|
|
expect "(config-if)#"
|
|
send "switchport access vlan {{ pillar['vlans'][name] }}\r"
|
|
expect "(config-if)#"
|
|
send "exit\r"
|
|
expect "(config)#"
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
{%- endfor %}
|