From 1335b5454353394c15cae6359dd197da05b6f07c Mon Sep 17 00:00:00 2001 From: sigopi Date: Wed, 13 Nov 2019 15:07:17 +0530 Subject: [PATCH 1/5] Support added to fix template role structure --- README.md | 21 ++++++++++++------- defaults/main.yml | 4 ---- meta/main.yml | 18 ++++++++++++++++ tasks/main.yml | 6 ++---- tasks/show_ip_bgp_summary.yaml | 5 ++--- tasks/show_ip_interface_brief.yaml | 3 +-- tasks/show_ip_vrf.yaml | 3 +-- tasks/show_lldp_neighbors.yaml | 3 +-- tasks/show_port-channel_summary.yaml | 3 +-- tasks/show_vlan.yaml | 3 +-- tasks/textfsm.yaml | 2 -- ... => dellos10_show_ip_bgp_summary.template} | 1 - ...dellos10_show_ip_interface_brief.template} | 0 ...template => dellos10_show_ip_vrf.template} | 1 - ... => dellos10_show_lldp_neighbors.template} | 1 - ...llos10_show_port-channel_summary.template} | 0 ...n.template => dellos10_show_vlan.template} | 1 - tests/inventory.yml | 10 +++++++++ tests/main.yml | 5 +++++ tests/test.yml | 7 +++++++ 20 files changed, 63 insertions(+), 34 deletions(-) delete mode 100644 defaults/main.yml create mode 100644 meta/main.yml rename templates/{dellos10/show_ip_bgp_summary.template => dellos10_show_ip_bgp_summary.template} (99%) rename templates/{dellos10/show_ip_interface_brief.template => dellos10_show_ip_interface_brief.template} (100%) rename templates/{dellos10/show_ip_vrf.template => dellos10_show_ip_vrf.template} (99%) rename templates/{dellos10/show_lldp_neighbors.template => dellos10_show_lldp_neighbors.template} (99%) rename templates/{dellos10/show_port-channel_summary.template => dellos10_show_port-channel_summary.template} (100%) rename templates/{dellos10/show_vlan.template => dellos10_show_vlan.template} (99%) create mode 100644 tests/inventory.yml create mode 100644 tests/main.yml create mode 100644 tests/test.yml diff --git a/README.md b/README.md index f7f6344..f9d0180 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ TEMPLATE role ============== -The dellos-template role provides access to structured data from show commands in devices running Dell EMC Networking Operating Systems.This role facilitates the TEXTFSM parsing engine. TextFSM is a template based state machine . It takes the raw string input from the CLI of network devices dellos10 , run them through a TEXTFSM template and return structured text in the form of a Python dictionary. +The dellos_template role provides access to structured data from show commands in devices running Dell EMC Networking Operating Systems.This role facilitates the TEXTFSM parsing engine. TextFSM is a template based state machine . It takes the raw string input from the CLI of network devices dellos10 , run them through a TEXTFSM template and return structured text in the form of a Python dictionary. It is highly customizable, because it works with separate template definitions, which contains variables and rules with regular expressions. This library is very helpful to parse any text-based CLI output from network devices. @@ -9,7 +9,7 @@ It is highly customizable, because it works with separate template definitions, Installation ------------ - ansible-galaxy install Dell-Networking.dellos-template + ansible-galaxy install Dell-Networking.dellos_template Connection variables @@ -33,24 +33,31 @@ Ansible Dell EMC Networking roles require connection information to establish co Dependencies ------------ -The *dellos-template* role is built on modules included in the core Ansible code. These modules were added in Ansible version 2.2.0.This role needs textfsm to be installed in the controller,if not it will be installed using ansible pip module. +The *dellos_template* role is built on modules included in the core Ansible code. These modules were added in Ansible version 2.2.0.This role needs textfsm to be installed in the controller,if not it will be installed using ansible pip module. Example playbook ---------------- -This example uses the *dellos-template* role to parse any text-based CLI output. It creates a *hosts* file with the switch details and corresponding variables. The hosts file should define the *ansible_network_os* variable with corresponding Dell EMC networking OS name.All the supported CLI commands are imported as tasks in tasks/main.yml. +This example uses the *dellos_template* role to parse any text-based CLI output. It creates a *hosts* file with the switch details and corresponding variables. The hosts file should define the *ansible_network_os* variable with corresponding Dell EMC networking OS name.All the supported CLI commands are imported as tasks in tasks/main.yml. +For the dellos_template role plugins to be used you may need to specify the actual path of role in ansible.cfg file. + +** Sample ansible.cfg** + + action_plugins = ../../roles/Dell-Networking.dellos-template/action_plugins + + **Sample hosts file** - leaf1 ansible_host= ansible_network_os="dellos10" + leaf1 ansible_host= ansible_network_os=dellos10 ansible_ssh_user=xxxxx ansible_ssh_pass=xxxxx **Simple playbook to setup system - leaf.yaml** - hosts: leaf1 roles: - - Dell-Networking.dellos-template + - Dell-Networking.dellos_template @@ -62,7 +69,7 @@ This example uses the *dellos-template* role to parse any text-based CLI output. hosts: leaf1 tasks: - import_role: - name: Dell-Networking.dellos-template + name: Dell-Networking.dellos_template tasks_from: show_ip_interface_brief.yaml diff --git a/defaults/main.yml b/defaults/main.yml deleted file mode 100644 index 84f23b0..0000000 --- a/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- - parser_path: "{{ parser_path }}/parser_templates/{{ ansible_network_os }}" - output_path: "{{ role_path }}/output/{{ ansible_network_os }}" - diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..8b7e30e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,18 @@ +# Copyright (c) 2019 Dell Inc. or its subsidiaries. All Rights Reserved. +--- +galaxy_info: + role_name: dellos_template + author: Dell EMC Networking Engineering + description: The dellos_temaplte role facilitates to provide the structrued ouptut from CLI in devices running on Dell EMC Networking Operating Systems. + license: Apache 2.0 + min_ansible_version: 2.2 + + platforms: + - name: DellOS + + galaxy_tags: + - networking + - dell + - emc + - dellemc + - dellos10 diff --git a/tasks/main.yml b/tasks/main.yml index d44c12f..ba679d3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,9 +2,6 @@ - name: dellos10 Dell-Networking.dellos-template test import_tasks: show_ip_interface_brief.yaml - - name: dellos10 Dell-Networking.dellos-template test - import_tasks: show_vlan.yaml - - name: dellos10 Dell-Networking.dellos-template test import_tasks: show_port-channel_summary.yaml @@ -17,4 +14,5 @@ - name: dellos10 Dell-Networking.dellos-template test import_tasks: show_ip_bgp_summary.yaml - + - name: dellos10 Dell-Networking.dellos-template test + import_tasks: show_vlan.yaml diff --git a/tasks/show_ip_bgp_summary.yaml b/tasks/show_ip_bgp_summary.yaml index 919ae6a..fcc4418 100644 --- a/tasks/show_ip_bgp_summary.yaml +++ b/tasks/show_ip_bgp_summary.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_ip_bgp_summary textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_ip_bgp_summary.template')}}" - content: "{{ output.stdout[0] }}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_ip_bgp_summary.template') }}" + content: "{{ output.stdout[0] }}" name: bgp_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/show_ip_interface_brief.yaml b/tasks/show_ip_interface_brief.yaml index b7e4c09..65dbf86 100644 --- a/tasks/show_ip_interface_brief.yaml +++ b/tasks/show_ip_interface_brief.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_ip_interface_brief textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_ip_interface_brief.template')}}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_ip_interface_brief.template') }}" content: " {{ output.stdout[0] }}" name: ip_interface_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/show_ip_vrf.yaml b/tasks/show_ip_vrf.yaml index 844a880..d85d469 100644 --- a/tasks/show_ip_vrf.yaml +++ b/tasks/show_ip_vrf.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_ip_vrf textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_ip_vrf.template')}}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_ip_vrf.template') }}" content: "{{ output.stdout[0] }}" name: vrf_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/show_lldp_neighbors.yaml b/tasks/show_lldp_neighbors.yaml index 56c7ba3..6e40627 100644 --- a/tasks/show_lldp_neighbors.yaml +++ b/tasks/show_lldp_neighbors.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_lldp_neighbors textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_lldp_neighbors.template')}}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_lldp_neighbors.template') }}" content: "{{ output.stdout[0] }}" name: lldp_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/show_port-channel_summary.yaml b/tasks/show_port-channel_summary.yaml index ed891dc..6deac1a 100644 --- a/tasks/show_port-channel_summary.yaml +++ b/tasks/show_port-channel_summary.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_port-channel_summary textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_port-channel_summary.template')}}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_port-channel_summary.template') }}" content: "{{ output.stdout[0] }}" name: port_channel_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/show_vlan.yaml b/tasks/show_vlan.yaml index 05ec1d4..87715cb 100644 --- a/tasks/show_vlan.yaml +++ b/tasks/show_vlan.yaml @@ -13,10 +13,9 @@ - name: PARSE THE OUTPUT for {{ ansible_network_os }} show_vlan textfsm_parser: - src: "{{lookup('file', './templates/{{ansible_network_os}}/show_vlan.template')}}" + src: "{{ lookup('file', './templates/{{ ansible_network_os }}_show_vlan.template') }}" content: "{{ output.stdout[0] }}" name: vlan_facts register: result vars: - ansible_network_os: dellos10 - diff --git a/tasks/textfsm.yaml b/tasks/textfsm.yaml index d38d39a..99394b4 100644 --- a/tasks/textfsm.yaml +++ b/tasks/textfsm.yaml @@ -1,5 +1,3 @@ #Install Textfsm - pip: name: textfsm - - diff --git a/templates/dellos10/show_ip_bgp_summary.template b/templates/dellos10_show_ip_bgp_summary.template similarity index 99% rename from templates/dellos10/show_ip_bgp_summary.template rename to templates/dellos10_show_ip_bgp_summary.template index 42523b1..52ddc28 100644 --- a/templates/dellos10/show_ip_bgp_summary.template +++ b/templates/dellos10_show_ip_bgp_summary.template @@ -14,4 +14,3 @@ Start ^(?!Neighbor)${Neighbor}\s+${AS}\s+${MsgRcvd}\s+${MsgSent}\s+${Status}\s+${State} -> Record EOF - diff --git a/templates/dellos10/show_ip_interface_brief.template b/templates/dellos10_show_ip_interface_brief.template similarity index 100% rename from templates/dellos10/show_ip_interface_brief.template rename to templates/dellos10_show_ip_interface_brief.template diff --git a/templates/dellos10/show_ip_vrf.template b/templates/dellos10_show_ip_vrf.template similarity index 99% rename from templates/dellos10/show_ip_vrf.template rename to templates/dellos10_show_ip_vrf.template index d4a6c96..c7e4d75 100644 --- a/templates/dellos10/show_ip_vrf.template +++ b/templates/dellos10_show_ip_vrf.template @@ -5,4 +5,3 @@ Start ^(?!VRF-Name)${VRFName}\s+${Interfaces} -> Record ^(?!VRF-Name)${VRFName} -> Record ^\s+${Interfaces} -> Record - diff --git a/templates/dellos10/show_lldp_neighbors.template b/templates/dellos10_show_lldp_neighbors.template similarity index 99% rename from templates/dellos10/show_lldp_neighbors.template rename to templates/dellos10_show_lldp_neighbors.template index ba4bd1b..3c93531 100644 --- a/templates/dellos10/show_lldp_neighbors.template +++ b/templates/dellos10_show_lldp_neighbors.template @@ -5,4 +5,3 @@ Value RemChassisId ([a-fA-F0-9:]{17}) Start ^${LocPortID}\s+${RemHostName}\s+${RemPortId}\s+${RemChassisId} -> Record - diff --git a/templates/dellos10/show_port-channel_summary.template b/templates/dellos10_show_port-channel_summary.template similarity index 100% rename from templates/dellos10/show_port-channel_summary.template rename to templates/dellos10_show_port-channel_summary.template diff --git a/templates/dellos10/show_vlan.template b/templates/dellos10_show_vlan.template similarity index 99% rename from templates/dellos10/show_vlan.template rename to templates/dellos10_show_vlan.template index e1a4c5e..f71e957 100644 --- a/templates/dellos10/show_vlan.template +++ b/templates/dellos10_show_vlan.template @@ -10,4 +10,3 @@ Start ^${Codes}\s+${NUM}\s+${Status}\s+${Description} -> Record ^${Codes}\s+${NUM}\s+${Status} -> Record ^\s+${Q}\s+${Ports} -> Record - diff --git a/tests/inventory.yml b/tests/inventory.yml new file mode 100644 index 0000000..ee9cb45 --- /dev/null +++ b/tests/inventory.yml @@ -0,0 +1,10 @@ +spine1 ansible_host=10.11.180.22 ansible_ssh_user=xxxxx ansible_ssh_pass=xxxxx ansible_network_os=dellos10 + +[spine] +spine1 + +[leaf] +#leaf1 + +[LeafAndSpineSwitch:children] +spine diff --git a/tests/main.yml b/tests/main.yml new file mode 100644 index 0000000..b10a62d --- /dev/null +++ b/tests/main.yml @@ -0,0 +1,5 @@ +--- +- hosts: LeafAndSpineSwitch + connection: network_cli + roles: + - Dell-Networking.dellos-template diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..34489b6 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,7 @@ +--- +- hosts: LeafAndSpineSwitch + connection: network_cli + tasks: + - import_role: + name: Dell-Networking.dellos-template + tasks_from: show_ip_interface_brief.yaml From da6aba698f636393aa47f1d954780558e5de7c09 Mon Sep 17 00:00:00 2001 From: sigopi Date: Wed, 13 Nov 2019 15:18:23 +0530 Subject: [PATCH 2/5] support added to inventory file --- tests/inventory.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/inventory.yml b/tests/inventory.yml index ee9cb45..2e3b95c 100644 --- a/tests/inventory.yml +++ b/tests/inventory.yml @@ -1,3 +1,4 @@ +--- spine1 ansible_host=10.11.180.22 ansible_ssh_user=xxxxx ansible_ssh_pass=xxxxx ansible_network_os=dellos10 [spine] From ee799b2e6bf2670c215e4159f15380c96263c37d Mon Sep 17 00:00:00 2001 From: sigopi Date: Wed, 13 Nov 2019 15:24:25 +0530 Subject: [PATCH 3/5] modified file extension under tests dir --- tests/{inventory.yml => inventory.yaml} | 0 tests/{main.yml => main.yaml} | 0 tests/{test.yml => test.yaml} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename tests/{inventory.yml => inventory.yaml} (100%) rename tests/{main.yml => main.yaml} (100%) rename tests/{test.yml => test.yaml} (100%) diff --git a/tests/inventory.yml b/tests/inventory.yaml similarity index 100% rename from tests/inventory.yml rename to tests/inventory.yaml diff --git a/tests/main.yml b/tests/main.yaml similarity index 100% rename from tests/main.yml rename to tests/main.yaml diff --git a/tests/test.yml b/tests/test.yaml similarity index 100% rename from tests/test.yml rename to tests/test.yaml From 4f1a58905bf29adbdf0dea46a03783271aaea88e Mon Sep 17 00:00:00 2001 From: sigopi Date: Wed, 13 Nov 2019 15:28:37 +0530 Subject: [PATCH 4/5] modify inventory file --- tests/inventory.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/inventory.yaml b/tests/inventory.yaml index 2e3b95c..56bf682 100644 --- a/tests/inventory.yaml +++ b/tests/inventory.yaml @@ -1,11 +1,21 @@ ---- -spine1 ansible_host=10.11.180.22 ansible_ssh_user=xxxxx ansible_ssh_pass=xxxxx ansible_network_os=dellos10 +spine1 ansible_host=10.11.182.25 ansible_net_os_name="dellos10" +spine2 ansible_host=10.16.151.220 ansible_net_os_name="dellos10" + +leaf1 ansible_host=10.11.182.23 ansible_net_os_name="dellos10" +leaf2 ansible_host=10.11.182.16 ansible_net_os_name="dellos10" +leaf3 ansible_host=10.11.182.17 ansible_net_os_name="dellos9" +leaf4 ansible_host=10.16.148.79 ansible_net_os_name="dellos6" [spine] spine1 +spine2 [leaf] -#leaf1 +leaf1 +leaf2 +leaf3 +leaf4 [LeafAndSpineSwitch:children] spine +leaf From c80e15f1c22fc1ce31165a23aaaab7f39d376fde Mon Sep 17 00:00:00 2001 From: sigopi Date: Wed, 13 Nov 2019 16:24:03 +0530 Subject: [PATCH 5/5] meta file update --- meta/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/main.yml b/meta/main.yml index 8b7e30e..0b9ed88 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ galaxy_info: role_name: dellos_template author: Dell EMC Networking Engineering - description: The dellos_temaplte role facilitates to provide the structrued ouptut from CLI in devices running on Dell EMC Networking Operating Systems. + description: The dellos_template role facilitates to provide the structured output from CLI in devices running on Dell EMC Networking Operating Systems. license: Apache 2.0 min_ansible_version: 2.2