network/salt/switches/HP-procurve-2824.expect

130 lines
3.2 KiB
Plaintext
Raw Normal View History

2016-11-26 22:57:34 +01:00
{# http://ftp.hp.com/pub/networking/software/2600-2800-4100-6108-MgmtConfig-Oct2005-59906023.pdf #}
2016-11-16 01:17:28 +01:00
{%- import_yaml "netmasks.yaml" as netmasks -%}
#!/usr/bin/expect -f
spawn ssh admin@{{ pillar['hosts-inet']['mgmt'][hostname] }}
expect "password: "
send "{{ switch['password'] }}\r"
expect "Press any key to continue"
send "\r"
expect "# "
send "configure terminal\r"
expect "(config)# "
send "hostname {{ hostname }}\r"
expect "(config)# "
send "snmp-server location \"{{ switch['location'] }}\"\r"
expect "(config)# "
send "snmp-server contact \"astro@spaceboyz.net\"\r"
expect "(config)# "
send "password manager\r"
expect "New password for Manager: "
send "{{ switch['password'] }}\r"
expect "Please retype new password for Manager: "
send "{{ switch['password'] }}\r"
expect "(config)# "
# TODO: ssh, password
2019-08-15 23:39:45 +02:00
{# Enable Logging #}
send "logging {{logging}}\r"
expect "(config)# "
send "logging facility local6\r"
expect "(config)# "
# todo ntp
# timesync sntp
2019-08-16 15:45:27 +02:00
# ip timep manual {#ntp#} interval 10
2019-08-15 23:39:45 +02:00
2016-11-16 01:17:28 +01:00
{%- for name, vlan in pillar['vlans'].items() %}
send "vlan {{ vlan }}\r"
expect "(vlan-{{ vlan }})#"
send "name {{ name }}\r"
expect "(vlan-{{ vlan }})#"
2019-08-15 23:53:22 +02:00
send "jumbo\r"
expect "(vlan-{{ vlan }})#"
2016-11-16 01:17:28 +01:00
{# Actually only used for mgmt_vlan, switches are not routers #}
{%- set net_hosts = pillar['hosts-inet'].get(name) %}
{%- set ipaddr = net_hosts and net_hosts.get(hostname) %}
{%- if ipaddr %}
send "ip address {{ ipaddr }} {{ netmasks[pillar['subnets-inet'][name].split('/')[1]] }}\r"
expect "(vlan-{{ vlan }})#"
{%- endif %}
send "exit\r"
expect "(config)# "
{%- if name == 'mgmt' %}
send "management-vlan {{ vlan }}\r"
expect "(config)# "
{%- else %}
# If not mgmt, reset all VLAN mappings
send "no vlan {{ vlan }} tagged all\r"
expect "(config)# "
send "no vlan {{ vlan }} untagged all\r"
expect "(config)# "
{%- endif %}
{%- endfor %}
{%- for name, conf in switch['ports'].items() %}
{%- if conf['mode'] == 'bond' %}
2016-11-16 01:17:28 +01:00
{%- if not conf.get('lacp', True) %}
2021-02-03 00:36:37 +01:00
send "trunk {{ conf['ports'] }} trk{{ conf['group'] }} trunk\r"
expect "(config)# "
{%- else %}
send "interface {{ conf['ports'] }} lacp active\r"
expect "(config)# "
send "trunk {{ conf['ports'] }} trk{{ conf['group'] }} lacp\r"
expect "(config)# "
2021-02-03 00:36:37 +01:00
{%- endif %}
{%- for vlan_name in conf['vlans'] %}
send "vlan {{ pillar['vlans'][vlan_name] }} tagged trk{{ conf['group'] }}\r"
expect "(config)# "
{%- endfor %}
{%- elif conf['mode'] == 'trunk' %}
send "no trunk {{ conf['ports'] }}\r"
expect "(config)# "
send "no interface {{ conf['ports'] }} lacp\r"
2016-11-16 01:17:28 +01:00
expect "(config)# "
{%- for vlan_name in conf['vlans'] %}
send "vlan {{ pillar['vlans'][vlan_name] }} tagged {{ conf['ports'] }}\r"
2016-11-16 01:17:28 +01:00
expect "(config)# "
{%- endfor %}
2016-11-16 01:17:28 +01:00
{%- elif conf['mode'] == 'access' %}
send "no trunk {{ conf['ports'] }}\r"
expect "(config)# "
2016-11-16 01:17:28 +01:00
send "vlan {{ pillar['vlans'][name] }} untagged {{ conf['ports'] }}\r"
expect "(config)# "
{%- endif %}
2016-11-26 02:42:20 +01:00
2016-11-26 03:02:27 +01:00
{%- if conf.get('nostp') %}
2016-11-26 02:42:20 +01:00
send "spanning-tree {{ conf['ports'] }} bpdu-filter\r"
expect "(config)# "
{%- endif %}
2016-11-16 01:17:28 +01:00
{%- endfor %}
2016-11-16 02:06:55 +01:00
send "exit\r"
expect "{{ hostname }}# "
2016-11-16 01:17:28 +01:00
send "write memory\r"
expect "{{ hostname }}# "
send "exit\r"
expect "{{ hostname }}> "
send "exit\r"
expect "Do you want to log out "
expect "y/n]? "
send "y"