Skip to content

Instantly share code, notes, and snippets.

View ganeshrn's full-sized avatar

Ganesh Nalawade ganeshrn

View GitHub Profile
@ganeshrn
ganeshrn / validate_task_run_output.txt
Last active December 14, 2020 08:07
validate task run output
TASK [validate interface for admin state] ***********************************************************************************************************
Monday 14 December 2020 11:05:37 +0530 (0:00:01.886) 0:00:27.014 *******
fatal: [nxos]: FAILED! => {"changed": false, "errors": [{"data_path": "Ethernet2/1.admin_state", "expected": "up", "found": "down", "json_path": "$.Ethernet2/1.admin_state", "message": "'down' does not match 'up'", "relative_schema": {"pattern": "up", "type": "string"}, "schema_path": "patternProperties.^.*.properties.admin_state.pattern", "validator": "pattern"}, {"data_path": "Ethernet2/10.admin_state", "expected": "up", "found": "down", "json_path": "$.Ethernet2/10.admin_state", "message": "'down' does not match 'up'", "relative_schema": {"pattern": "up", "type": "string"}, "schema_path": "patternProperties.^.*.properties.admin_state.pattern", "validator": "pattern"}], "msg": "Validation errors were found.\nAt 'patternProperties.^.*.properties.admin_state.pattern' 'down' does not
@ganeshrn
ganeshrn / validate_criteria.yaml
Created December 14, 2020 05:36
validate admin state criteria
- name: validate interface for admin state
ansible.utils.validate:
data: "{{ nxos_pyats_show_interface['parsed'] }}"
criteria:
- "{{ lookup('file', './criterias/nxos_show_interface_admin_criteria.json') | from_json }}"
engine: ansible.utils.jsonschema
ignore_errors: true
register: result
- name: print the interface names that does not satisfy the desired state
@ganeshrn
ganeshrn / validate_criteria.json
Created December 14, 2020 05:28
jsonschema criteria for interface up state
{
"type": "object",
"patternProperties": {
"^.*": {
"type": "object",
"properties": {
"admin_state": {
"type": "string",
"pattern": "up"
}
@ganeshrn
ganeshrn / nxos_pyats_show_interface['parsed']
Created December 14, 2020 04:40
nxos show interface parsed outptu
{
"Ethernet2/1": {
"admin_state": "down",
"auto_mdix": "off",
"auto_negotiate": false,
"bandwidth": 1000000,
"beacon": "off",
"counters": {
"in_bad_etype_drop": 0,
"in_broadcast_pkts": 0,
@ganeshrn
ganeshrn / nxos_pyats_show_interface.yaml
Last active December 14, 2020 04:35
Get interface state in structured format on nxos
---
- hosts: nxos
connection: ansible.netcommon.network_cli
gather_facts: false
vars:
ansible_network_os: cisco.nxos.nxos
ansible_user: "changeme"
ansible_password: "changeme"
tasks:
- name: "Fetch interface state and parse with pyats"
@ganeshrn
ganeshrn / libssh_playbook_test.yaml
Created October 29, 2020 16:50
Playbook to test libssh configuration settings
- hosts: "changeme"
gather_facts: no
connection: ansible.netcommon.network_cli
vars:
ansible_network_os: cisco.ios.ios
ansible_user: "changeme"
ansible_password: "changeme"
ansible_network_cli_ssh_type: libssh
tasks:
- name: run show version command
@ganeshrn
ganeshrn / validate_filter.py
Created October 20, 2020 13:09
validate_filter.py
from copy import deepcopy
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
from ansible_collections.ansible.utils.plugins.module_utils.validator.base import (
load_validator,
)
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import (
to_list,
)
@ganeshrn
ganeshrn / show_interface_schema_iosxr.json
Created October 12, 2020 13:56
show_interface_schema_iosxr
{
"type" : "object",
"patternProperties": {
"^[a-zA-Z]+$": {
"type": "object",
"properties": {
"auto_negotiate": {
"type": "boolean"
},
"enabled": {
@ganeshrn
ganeshrn / show_interface_out_json_iosxr.json
Created October 12, 2020 13:55
show_interface_out_json_iosxr
{
"GigabitEthernet0/0/0/0": {
"auto_negotiate": false,
"bandwidth": 1000000,
"bandwidth_max": 1000000,
"carrier_delay_up": 10,
"counters": {
"carrier_transitions": 1,
"in_abort": 0,
"in_broadcast_pkts": 0,
@ganeshrn
ganeshrn / interfac_cfg.json
Created September 30, 2020 14:10
interfac_cfg
intf_config = {
"interfaces": {
"interface": [
{
"config": {
"description": "configured by Ansible - 1",
"enabled": "True",
"loopback-mode": "False",
"mtu": "1024",
"name": "loopback0000",