Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/get_facts.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ The default value is `all`

#### Current supported values for subset are

<<<<<<< HEAD
* default
* bridging
* bgp
Expand All @@ -156,6 +157,11 @@ is made by the playbook. Normally this value does not need to be modified but
can be used to pass a custom command map to the function.

The default value is `vars/get_facts_command_map.yaml`
=======
* system
* hostname

>>>>>>> fdbc120... adds initial set of parser templates

## Notes

Expand Down
39 changes: 39 additions & 0 deletions parser_templates/cli/show_cdp_entry_all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: match cdp sections
pattern_match:
regex: "^----------------------------------------"
match_all: yes
match_greedy: yes
register: context

- name: match cpd values
pattern_group:
- name: match name
pattern_match:
regex: "Device ID:(|\\s)(.+)\\("
content: "{{ item }}"
register: device_id

- name: match interface
pattern_match:
regex: "Interface: (.+), Port ID \\(outgoing port\\): (.+)"
content: "{{ item }}"
register: interface

loop: "{{ context }}"
register: values

- name: build cdp template
json_template:
template:
- key: "{{ item.device_id.matches.1 }}"
object:
- key: local_port
value: "{{ item.interface.matches.0 }}"
- key: remote_port
value: "{{ item.interface.matches.1}}"
loop: "{{ values }}"
register: neighbors
export: yes
export_as: dict
extend: cisco_nxos
84 changes: 84 additions & 0 deletions parser_templates/cli/show_interface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
- name: match interface sections
pattern_match:
regex: "^\\S+ is (up|down)"
match_all: yes
match_greedy: yes
register: context

- name: match interface values
pattern_group:
- name: match name
pattern_match:
regex: "^(.+) is (\\w+)"
content: "{{ item }}"
register: name

- name: match admin state
pattern_match:
regex: "admin state is (\\S+)"
content: "{{ item }}"
register: admin_state

- name: match mac address
pattern_match:
regex: "Hardware: Ethernet, address: ([\\d|\\w]{4}.[\\d|\\w]{4}.[\\d|\\w]{4})"
content: "{{ item }}"
register: mac_addr

- name: match description value
pattern_match:
regex: "Description: (.*)"
content: "{{ item }}"
register: description

- name: match mtu value
pattern_match:
regex: "MTU (\\d+)"
content: "{{ item }}"
register: mtu

- name: match ipv4 address
pattern_match:
regex: "Internet Address is (.+)"
content: "{{ item }}"
register: ipv4addr

- name: match port mode
pattern_match:
regex: "Port mode is (.+)"
content: "{{ item }}"
register: port_mode

loop: "{{ context }}"
register: values

- name: build interface template
json_template:
template:
- key: "{{ item.name.matches.0 }}"
object:
- key: oper_status
value: "{{ item.name.matches.1 }}"
- key: admin_status
value: "{{ item.admin_state.matches.0}}"
- key: mac_address
value: "{{ item.mac_addr.matches.0 }}"
- key: ipv4
object:
- key: address
value: "{{ item.ipv4addr.matches.0.split('/')[0] }}"
- key: masklen
value: "{{ item.ipv4addr.matches.0.split('/')[1] }}"
when: item.ipv4addr.matches
- key: description
value: "{{ item.description.matches.0 }}"
- key: mtu
value: "{{ item.mtu.matches.0 }}"
- key: port_mode
value: "{{ item.port_mode.matches.0}}"
loop: "{{ values }}"
register: interfaces
export: yes
export_as: dict
extend: cisco_nxos
30 changes: 30 additions & 0 deletions parser_templates/cli/show_version.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
<<<<<<< HEAD
- name: parser meta data
parser_metadata:
version: 1.0
Expand Down Expand Up @@ -113,3 +114,32 @@
value: "{{ cpu_mem.matches.1 }}"
- key: unit
value: "{{ cpu_mem.matches.2 }}"
=======
- name: parse softare version
pattern_match:
regex: "\\s{2}NXOS: version (\\S+)"
register: version

- name: parse image file
pattern_match:
regex: "\\s{2}NXOS image file is: (\\S+)"
register: image

- name: parse system name
pattern_match:
regex: "Device name: (\\S+)"
register: hostname

- name: build nxos system facts
json_template:
template:
- key: version
value: "{{ version.matches.0 }}"
- key: image_file
value: "{{ image.matches.0 }}"
- key: hostname
value: "{{ hostname.matches.0 }}"
register: system
export: yes
extend: cisco_nxos
>>>>>>> fdbc120... adds initial set of parser templates
15 changes: 15 additions & 0 deletions tasks/run_cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: run command and parse output
cli:
command: "{{ nxos_command }}"
parser: "{{ parser }}"
with_first_found:
- files:
- "{{ nxos_parser }}"
paths:
- "{{ playbook_dir }}/parser_templates/nxos"
- "~/.ansible/ansible_network/parser_templates/nxos"
- "/etc/ansible/ansible_network/parser_templates/nxos"
- "{{ role_path }}/parser_templates"
loop_control:
loop_var: parser