Skip to content

Commit

Permalink
Merge pull request #3 from SindhuParvathi-Gopi/master
Browse files Browse the repository at this point in the history
Support added to fix template role structure format issue
  • Loading branch information
skg-net authored Nov 14, 2019
2 parents 5cfaa43 + c80e15f commit 418132c
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 34 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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.


Installation
------------

ansible-galaxy install Dell-Networking.dellos-template
ansible-galaxy install Dell-Networking.dellos_template


Connection variables
Expand All @@ -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= <ip_address> ansible_network_os="dellos10"
leaf1 ansible_host= <ip_address> 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



Expand All @@ -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


Expand Down
4 changes: 0 additions & 4 deletions defaults/main.yml

This file was deleted.

18 changes: 18 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 2 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
5 changes: 2 additions & 3 deletions tasks/show_ip_bgp_summary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tasks/show_ip_interface_brief.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tasks/show_ip_vrf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tasks/show_lldp_neighbors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tasks/show_port-channel_summary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tasks/show_vlan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 0 additions & 2 deletions tasks/textfsm.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#Install Textfsm
- pip:
name: textfsm


Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ Start
^(?!Neighbor)${Neighbor}\s+${AS}\s+${MsgRcvd}\s+${MsgSent}\s+${Status}\s+${State} -> Record

EOF

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Start
^(?!VRF-Name)${VRFName}\s+${Interfaces} -> Record
^(?!VRF-Name)${VRFName} -> Record
^\s+${Interfaces} -> Record

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Value RemChassisId ([a-fA-F0-9:]{17})

Start
^${LocPortID}\s+${RemHostName}\s+${RemPortId}\s+${RemChassisId} -> Record

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Start
^${Codes}\s+${NUM}\s+${Status}\s+${Description} -> Record
^${Codes}\s+${NUM}\s+${Status} -> Record
^\s+${Q}\s+${Ports} -> Record

21 changes: 21 additions & 0 deletions tests/inventory.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: LeafAndSpineSwitch
connection: network_cli
roles:
- Dell-Networking.dellos-template
7 changes: 7 additions & 0 deletions tests/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: LeafAndSpineSwitch
connection: network_cli
tasks:
- import_role:
name: Dell-Networking.dellos-template
tasks_from: show_ip_interface_brief.yaml

0 comments on commit 418132c

Please sign in to comment.