From 4710090a661a90735ab4ffeac19e35bed162b51a Mon Sep 17 00:00:00 2001 From: Naved Ansari Date: Thu, 26 Jan 2023 18:10:23 -0500 Subject: [PATCH 1/3] Don't match commands against running-config because generating the running-config can take a long time. --- .../roles/network-runner/providers/nos/conf_access_port.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml b/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml index 79366c7..c9ba9ad 100644 --- a/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml @@ -6,6 +6,7 @@ - "shutdown" parents: - "interface {{ port_name }}" + match: none connection: network_cli - name: "nos: enable switchport in access mode" @@ -16,6 +17,7 @@ - "no shutdown" parents: - "interface {{ port_name }}" + match: none connection: network_cli - name: "nos: enable rstp" @@ -24,6 +26,7 @@ - "no spanning-tree shutdown" parents: - "interface {{ port_name }}" + match: none connection: network_cli when: stp_edge @@ -33,4 +36,5 @@ - "switchport access vlan {{ _vlan_id }}" parents: - "interface {{ port_name }}" + match: none connection: network_cli From 13d9970d5ae4766793f194d43dc5e1c729dbb352 Mon Sep 17 00:00:00 2001 From: Naved Ansari Date: Thu, 26 Jan 2023 18:38:25 -0500 Subject: [PATCH 2/3] Stack all the commands into one command so we don't make multiple round trips This significantly improves performance. --- .../providers/nos/conf_access_port.yaml | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml b/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml index c9ba9ad..5a681f6 100644 --- a/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/conf_access_port.yaml @@ -1,38 +1,13 @@ --- -- name: "nos: reset interface to default" +- name: "nos: restore config and then configure access port" community.network.nos_config: lines: - "no switchport" - "shutdown" - parents: - - "interface {{ port_name }}" - match: none - connection: network_cli - -- name: "nos: enable switchport in access mode" - community.network.nos_config: - lines: - "switchport" - "switchport mode access" - "no shutdown" - parents: - - "interface {{ port_name }}" - match: none - connection: network_cli - -- name: "nos: enable rstp" - community.network.nos_config: - lines: - "no spanning-tree shutdown" - parents: - - "interface {{ port_name }}" - match: none - connection: network_cli - when: stp_edge - -- name: "nos: set access mode vlan" - community.network.nos_config: - lines: - "switchport access vlan {{ _vlan_id }}" parents: - "interface {{ port_name }}" From 85c91ce8bc6d39e8d3c31849ff62255af8dc166b Mon Sep 17 00:00:00 2001 From: Naved Ansari Date: Mon, 30 Jan 2023 12:21:04 -0500 Subject: [PATCH 3/3] Make other functions faster the same way we did in the previous commit. --- .../providers/nos/add_trunk_vlan.yaml | 1 + .../providers/nos/conf_trunk_port.yaml | 28 +++---------------- .../providers/nos/create_vlan.yaml | 1 + .../providers/nos/delete_port.yaml | 1 + .../providers/nos/delete_trunk_vlan.yaml | 1 + .../providers/nos/delete_vlan.yaml | 1 + 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/etc/ansible/roles/network-runner/providers/nos/add_trunk_vlan.yaml b/etc/ansible/roles/network-runner/providers/nos/add_trunk_vlan.yaml index ab0ff81..77ff9e3 100644 --- a/etc/ansible/roles/network-runner/providers/nos/add_trunk_vlan.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/add_trunk_vlan.yaml @@ -5,4 +5,5 @@ - "switchport trunk allowed vlan add {{ _vlan_id }}" parents: - "interface {{ port_name }}" + match: none connection: network_cli diff --git a/etc/ansible/roles/network-runner/providers/nos/conf_trunk_port.yaml b/etc/ansible/roles/network-runner/providers/nos/conf_trunk_port.yaml index 4c82cd4..3130998 100644 --- a/etc/ansible/roles/network-runner/providers/nos/conf_trunk_port.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/conf_trunk_port.yaml @@ -1,48 +1,28 @@ --- -- name: "nos: reset interface to default" +- name: "nos: reset interface to default and then configure it in trunk mode with native-vlan" community.network.nos_config: lines: - "no switchport" - "shutdown" - parents: - - "interface {{ port_name }}" - connection: network_cli - -- name: "nos: enable switchport in trunk mode and disable tagging of native-vlan" - community.network.nos_config: - lines: - "switchport" - "switchport mode trunk" - "no switchport trunk tag native-vlan" - "no shutdown" - parents: - - "interface {{ port_name }}" - connection: network_cli - -- name: "nos: enable rstp" - community.network.nos_config: - lines: - "no spanning-tree shutdown" - parents: - - "interface {{ port_name }}" - connection: network_cli - when: stp_edge - -- name: "nos: set native vlan" - community.network.nos_config: - lines: - "switchport trunk allowed vlan add {{ _vlan_id }}" - "switchport trunk native-vlan {{ _vlan_id }}" parents: - "interface {{ port_name }}" + match: none connection: network_cli -- name: "nos: add trunk vlan(s)" +- name: "nos: add the remainder of trunk vlan(s)" community.network.nos_config: lines: - "switchport trunk allowed vlan add {{ t_vlan }}" parents: - "interface {{ port_name }}" + match: none loop: "{{ trunked_vlans }}" loop_control: loop_var: t_vlan diff --git a/etc/ansible/roles/network-runner/providers/nos/create_vlan.yaml b/etc/ansible/roles/network-runner/providers/nos/create_vlan.yaml index b07c1ed..2a84ba9 100644 --- a/etc/ansible/roles/network-runner/providers/nos/create_vlan.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/create_vlan.yaml @@ -5,4 +5,5 @@ - "name {{ _vlan_name }}" parents: - "interface vlan {{ _vlan_id }}" + match: none connection: network_cli diff --git a/etc/ansible/roles/network-runner/providers/nos/delete_port.yaml b/etc/ansible/roles/network-runner/providers/nos/delete_port.yaml index 9cabbc3..215d81c 100644 --- a/etc/ansible/roles/network-runner/providers/nos/delete_port.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/delete_port.yaml @@ -6,4 +6,5 @@ - "shutdown" parents: - "interface {{ port_name }}" + match: none connection: network_cli diff --git a/etc/ansible/roles/network-runner/providers/nos/delete_trunk_vlan.yaml b/etc/ansible/roles/network-runner/providers/nos/delete_trunk_vlan.yaml index ea4b568..38d3a33 100644 --- a/etc/ansible/roles/network-runner/providers/nos/delete_trunk_vlan.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/delete_trunk_vlan.yaml @@ -5,4 +5,5 @@ - "switchport trunk allowed vlan remove {{ _vlan_id }}" parents: - "interface {{ port_name }}" + match: none connection: network_cli diff --git a/etc/ansible/roles/network-runner/providers/nos/delete_vlan.yaml b/etc/ansible/roles/network-runner/providers/nos/delete_vlan.yaml index c6c9ab8..3c1ed6d 100644 --- a/etc/ansible/roles/network-runner/providers/nos/delete_vlan.yaml +++ b/etc/ansible/roles/network-runner/providers/nos/delete_vlan.yaml @@ -3,4 +3,5 @@ community.network.nos_config: lines: - "no interface vlan {{ _vlan_id }}" + match: none connection: network_cli