From 4260ec24055f066078e7671314c5112497bd4942 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 7 Nov 2021 01:18:25 +0100 Subject: [PATCH] salt/switches: sort output stably --- salt/switches/3com-4200G.expect | 10 +++++----- salt/switches/HP-procurve-2824.expect | 8 ++++---- salt/switches/TL-SG3210.expect | 8 ++++---- salt/switches/linksys-srw2048.expect | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/salt/switches/3com-4200G.expect b/salt/switches/3com-4200G.expect index 57e9860..944d044 100644 --- a/salt/switches/3com-4200G.expect +++ b/salt/switches/3com-4200G.expect @@ -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" diff --git a/salt/switches/HP-procurve-2824.expect b/salt/switches/HP-procurve-2824.expect index cbc7180..ee5c467 100644 --- a/salt/switches/HP-procurve-2824.expect +++ b/salt/switches/HP-procurve-2824.expect @@ -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 %} diff --git a/salt/switches/TL-SG3210.expect b/salt/switches/TL-SG3210.expect index b4586b2..8f9dd9e 100644 --- a/salt/switches/TL-SG3210.expect +++ b/salt/switches/TL-SG3210.expect @@ -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" diff --git a/salt/switches/linksys-srw2048.expect b/salt/switches/linksys-srw2048.expect index 4ef960a..019310e 100644 --- a/salt/switches/linksys-srw2048.expect +++ b/salt/switches/linksys-srw2048.expect @@ -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"