salt/switches: sort output stably

This commit is contained in:
Astro 2021-11-07 01:18:25 +01:00
parent f54fa47fd8
commit 4260ec2405
4 changed files with 20 additions and 20 deletions

View File

@ -44,7 +44,7 @@ send "info-center source default channel loghost log level informational\r"
expect "]"
{%- for name, vlan in pillar['vlans'].items() %}
{%- for name, vlan in pillar['vlans'].items()|sort(attribute='1') %}
send "vlan {{ vlan }}\r"
expect -- "-vlan{{ vlan }}]"
send "name {{ name }}\r"
@ -65,7 +65,7 @@ send "quit\r"
expect "{{ hostname }}]"
{%- endfor %}
{%- for name, conf in switch['ports'].items() %}
{%- for name, conf in switch['ports'].items()|sort(attribute='1.ports') %}
{%- if conf['mode'] == 'trunk' or conf['mode'] == 'bond' %}
{%- if conf['mode'] == 'bond' %}
send "link-aggregation group {{ conf['group'] }} mode static\r"
@ -78,7 +78,7 @@ expect {
send "link-aggregation group {{ conf['group'] }} description {{name}}\r"
expect "]"
{%- endif %}
{%- for port in conf['ports'] %}
{%- for port in conf['ports']|sort %}
send "interface {{ port }}\r"
expect "]"
send "undo stp edged-port\r"
@ -104,7 +104,7 @@ expect "]"
# Deconfigure all but mgmt vlan
send "undo port trunk permit vlan 2 to 4094\r"
expect "]"
{%- for vlan_name in conf['vlans'] %}
{%- for vlan_name in conf['vlans']|sort %}
send "port trunk permit vlan {{ pillar['vlans'][vlan_name] }}\r"
expect "]"
{%- endfor %}
@ -119,7 +119,7 @@ expect "{{ hostname }}]"
{%- endfor %}
{%- elif conf['mode'] == 'access' %}
{%- for port in conf['ports'] %}
{%- for port in conf['ports']|sort %}
send "interface {{ port }}\r"
expect "]"
send "undo port link-aggregation group\r"

View File

@ -36,7 +36,7 @@ expect "(config)# "
# timesync sntp
# ip timep manual {#ntp#} interval 10
{%- for name, vlan in pillar['vlans'].items() %}
{%- for name, vlan in pillar['vlans'].items()|sort(attribute='1') %}
send "vlan {{ vlan }}\r"
expect "(vlan-{{ vlan }})#"
@ -70,7 +70,7 @@ expect "(config)# "
{%- endfor %}
{%- for name, conf in switch['ports'].items() %}
{%- for name, conf in switch['ports'].items()|sort(attribute='1.ports') %}
{%- if conf['mode'] == 'bond' %}
{%- if not conf.get('lacp', True) %}
@ -84,7 +84,7 @@ send "trunk {{ conf['ports'] }} trk{{ conf['group'] }} lacp\r"
expect "(config)# "
{%- endif %}
{%- for vlan_name in conf['vlans'] %}
{%- for vlan_name in conf['vlans']|sort %}
send "vlan {{ pillar['vlans'][vlan_name] }} tagged trk{{ conf['group'] }}\r"
expect "(config)# "
{%- endfor %}
@ -95,7 +95,7 @@ expect "(config)# "
send "no interface {{ conf['ports'] }} lacp\r"
expect "(config)# "
{%- for vlan_name in conf['vlans'] %}
{%- for vlan_name in conf['vlans']|sort %}
send "vlan {{ pillar['vlans'][vlan_name] }} tagged {{ conf['ports'] }}\r"
expect "(config)# "
{%- endfor %}

View File

@ -48,7 +48,7 @@ expect "(config-line)#"
send "exit\r"
expect "(config)#"
{%- for name, vlan in pillar['vlans'].items() %}
{%- for name, vlan in pillar['vlans'].items()|sort(attribute='1') %}
{%- if name != 'mgmt' %}
send "vlan {{ vlan }}\r"
expect "(config-vlan)#"
@ -72,7 +72,7 @@ expect "(config)#"
{%- endfor %}
{%- set group = 0 %}
{%- for name, conf in switch['ports'].items() %}
{%- for name, conf in switch['ports'].items()|sort(attribute='1.ports') %}
{%- if conf['mode'] == 'trunk' or conf['mode'] == 'bond' %}
send "interface range gigabitEthernet 1/0/{{ conf['ports'] }}\r"
expect "(config-if-range)#"
@ -84,7 +84,7 @@ expect "(config-if-range)#"
#send "port-channel load-balance src-dst-ip\r"
#expect "(config-if-range)#"
{%- set vlan_ids = [] %}
{%- for name in conf['vlans'] %}
{%- for name in conf['vlans']|sort %}
{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %}
{%- endif %}
{%- endfor %}
@ -93,7 +93,7 @@ expect "(config-if-range)#"
send "exit\r"
expect "(config)#"
{%- elif conf['mode'] == 'access' %}
{%- for port in conf['ports'] %}
{%- for port in conf['ports']|sort %}
send "interface range gigabitEthernet 1/0/{{ port }}\r"
expect "(config-if-range)#"
send "switchport mode access\r"

View File

@ -25,13 +25,13 @@ send "management vlan 4094\r"
expect "(config)# "
send "vlan database\r"
expect "(config-vlan)# "
{%- for name, vlan in pillar['vlans'].items() %}
{%- for name, vlan in pillar['vlans'].items()|sort(attribute='1') %}
send "vlan {{ vlan }}\r"
expect "(config-vlan)#"
{%- endfor %}
send "exit\r"
expect "(config)#"
{%- for name, vlan in pillar['vlans'].items() %}
{%- for name, vlan in pillar['vlans'].items()|sort(attribute='1') %}
send "interface vlan {{ vlan }}\r"
expect "(config-if)#"
send "name {{ name }}\r"
@ -40,10 +40,10 @@ send "exit\r"
expect "(config)#"
{%- endfor %}
{%- for name, conf in switch['ports'].items() %}
{%- for name, conf in switch['ports'].items()|sort(attribute='1.ports') %}
{%- if conf['mode'] == 'trunk' %}
{%- for port in conf['ports'] %}
{%- for port in conf['ports']|sort %}
send "interface ethernet {{ port }}\r"
expect "(config-if)#"
send "no channel-group\r"
@ -51,7 +51,7 @@ expect "(config-if)#"
send "switchport mode trunk\r"
expect "(config-if)#"
{%- set vlan_ids = [] %}
{%- for name in conf['vlans'] %}
{%- for name in conf['vlans']|sort %}
{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %}
{%- endif %}
{%- endfor %}
@ -77,7 +77,7 @@ expect "(config-if)#"
send "switchport mode trunk\r"
expect "(config-if)#"
{%- set vlan_ids = [] %}
{%- for name in conf['vlans'] %}
{%- for name in conf['vlans']|sort %}
{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %}
{%- endif %}
{%- endfor %}
@ -88,7 +88,7 @@ send "exit\r"
expect "(config)#"
{%- elif conf['mode'] == 'access' %}
{%- for port in conf['ports'] %}
{%- for port in conf['ports']|sort %}
send "interface ethernet {{ port }}\r"
expect "(config-if)#"
send "no channel-group\r"