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..0b9ed88 --- /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_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 + + 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.yaml b/tests/inventory.yaml new file mode 100644 index 0000000..56bf682 --- /dev/null +++ b/tests/inventory.yaml @@ -0,0 +1,21 @@ +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 +leaf2 +leaf3 +leaf4 + +[LeafAndSpineSwitch:children] +spine +leaf diff --git a/tests/main.yaml b/tests/main.yaml new file mode 100644 index 0000000..b10a62d --- /dev/null +++ b/tests/main.yaml @@ -0,0 +1,5 @@ +--- +- hosts: LeafAndSpineSwitch + connection: network_cli + roles: + - Dell-Networking.dellos-template diff --git a/tests/test.yaml b/tests/test.yaml new file mode 100644 index 0000000..34489b6 --- /dev/null +++ b/tests/test.yaml @@ -0,0 +1,7 @@ +--- +- hosts: LeafAndSpineSwitch + connection: network_cli + tasks: + - import_role: + name: Dell-Networking.dellos-template + tasks_from: show_ip_interface_brief.yaml