Adding Netbox

This commit is contained in:
Patrick Toal
2019-05-06 00:34:45 -04:00
parent 832502de34
commit 6e2205a046
278 changed files with 12767 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
[defaults]
host_key_checking = False
retry_files_enabled = False
gathering = explicit

View File

@@ -0,0 +1,4 @@
---
parser_path: "{{ role_path }}/parser_templates/{{ ansible_network_os }}"
output_path: "{{ role_path }}/output/{{ ansible_network_os }}"
export_type: "list"

View File

@@ -0,0 +1,85 @@
GigabitEthernet0/0 is up, line protocol is up
Hardware is iGbE, address is 5e00.0002.0000 (bia 5e00.0002.0000)
Description: OOB Management
Internet address is 10.8.38.65/24
MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 253/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, Auto Speed, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 2000 bits/sec, 2 packets/sec
5 minute output rate 2000 bits/sec, 2 packets/sec
4973387 packets input, 816226566 bytes, 0 no buffer
Received 228869 broadcasts (0 IP multicasts)
461509 runts, 0 giants, 0 throttles
461509 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
3316083 packets output, 432440225 bytes, 0 underruns
0 output errors, 0 collisions, 3 interface resets
2303378 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
1 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
GigabitEthernet0/1 is up, line protocol is up
Hardware is iGbE, address is fa16.3e4e.c5e5 (bia fa16.3e4e.c5e5)
Description: test-interface
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, 1Gbps, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 4d07h, output 4d07h, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
89815 packets input, 27598643 bytes, 0 no buffer
Received 1 broadcasts (0 IP multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
404016 packets output, 27896846 bytes, 0 underruns
0 output errors, 0 collisions, 51 interface resets
89728 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
28 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
GigabitEthernet0/2 is up, line protocol is up
Hardware is iGbE, address is fa16.3eca.c938 (bia fa16.3eca.c938)
Description: test-interface-2
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, 1Gbps, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 3w1d, output 00:00:08, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
487240 packets input, 36339153 bytes, 0 no buffer
Received 8 broadcasts (0 IP multicasts)
183253 runts, 0 giants, 0 throttles
183253 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
1115575 packets output, 73936479 bytes, 0 underruns
0 output errors, 0 collisions, 12 interface resets
0 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
5 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out

View File

@@ -0,0 +1,44 @@
Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Tue 22-Mar-16 16:19 by prod_rel_team
ROM: Bootstrap program is IOSv
an-ios-01 uptime is 10 weeks, 6 days, 22 hours, 30 minutes
System returned to ROM by reload
System image file is "flash0:/vios-adventerprisek9-m"
Last reload reason: Unknown reason
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Cisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.
Processor board ID 92O0KON393UV5P77JRKZ5
4 Gigabit Ethernet interfaces
DRAM configuration is 72 bits wide with parity disabled.
256K bytes of non-volatile configuration memory.
2097152K bytes of ATA System CompactFlash 0 (Read/Write)
0K bytes of ATA CompactFlash 1 (Read/Write)
0K bytes of ATA CompactFlash 2 (Read/Write)
10080K bytes of ATA CompactFlash 3 (Read/Write)
Configuration register is 0x0

View File

@@ -0,0 +1,61 @@
---
- name: parser meta data
parser_metadata:
version: 1.0
command: show interface
network_os: ios
- name: match sections
pattern_match:
regex: "^(\\S+) is up,"
match_all: true
match_greedy: true
register: section
- name: match interface values
pattern_group:
- name: match name
pattern_match:
regex: "^(\\S+)"
content: "{{ item }}"
register: name
- name: match hardware
pattern_match:
regex: "Hardware is (\\S+),"
content: "{{ item }}"
register: type
- name: match mtu
pattern_match:
regex: "MTU (\\d+)"
content: "{{ item }}"
register: mtu
- name: match description
pattern_match:
regex: "Description: (.*)"
content: "{{ item }}"
register: description
loop: "{{ section }}"
register: interfaces
- name: generate json data structure
json_template:
template:
- key: "{{ item.name.matches.0 }}"
object:
- key: config
object:
- key: name
value: "{{ item.name.matches.0 }}"
- key: type
value: "{{ item.type.matches.0 }}"
- key: mtu
value: "{{ item.mtu.matches.0 }}"
- key: description
value: "{{ item.description.matches.0 }}"
loop: "{{ interfaces }}"
export: true
export_as: "{{ export_type }}"
register: interface_facts

View File

@@ -0,0 +1,61 @@
---
- name: parser meta data
parser_metadata:
version: 1.0
command: show interface
network_os: ios
- name: match sections
pattern_match:
regex: "^(\\S+) is up,"
match_all: true
match_greedy: true
register: section
- name: match interface values
pattern_group:
- name: match name
pattern_match:
regex: "^(\\S+)"
content: "{{ item }}"
register: name
- name: match hardware
pattern_match:
regex: "Hardware is (\\S+),"
content: "{{ item }}"
register: type
- name: match mtu
pattern_match:
regex: "MTU (\\d+)"
content: "{{ item }}"
register: mtu
- name: match description
pattern_match:
regex: "Description: (.*)"
content: "{{ item }}"
register: description
loop: "{{ section }}"
register: interfaces
- name: generate json data structure
json_template:
template:
- key: "{{ item.name.matches.0 }}"
object:
- key: config
object:
- key: name
value: "{{ item.name.matches.0 }}"
- key: type
value: "{{ item.type.matches.0 }}"
- key: mtu
value: "{{ item.mtu.matches.0 }}"
- key: description
value: "{{ item.description.matches.0 }}"
loop: "{{ interfaces }}"
export: true
register: interface_facts
extend: test.extension

View File

@@ -0,0 +1,48 @@
---
- name: parser meta data
parser_metadata:
version: 1.0
command: show version
network_os: ios
- name: match version
pattern_match:
regex: "Version (\\S+),"
register: version
- name: match model
pattern_match:
regex: "^Cisco (.+) \\(revision"
register: model
- name: match image
pattern_match:
regex: "^System image file is (\\S+)"
register: image
- name: match uptime
pattern_match:
regex: "uptime is (.+)"
register: uptime
- name: match total memory
pattern_match:
regex: "with (\\S+)/(\\w*) bytes of memory"
register: total_mem
- name: match free memory
pattern_match:
regex: "with \\w*/(\\S+) bytes of memory"
register: free_mem
- name: export system facts to playbook
set_vars:
model: "{{ model.matches.0 }}"
image_file: "{{ image.matches.0 }}"
uptime: "{{ uptime.matches.0 }}"
version: "{{ version.matches.0 }}"
memory:
total: "{{ total_mem.matches.0 }}"
free: "{{ free_mem.matches.0 }}"
export: true
register: system_facts

View File

@@ -0,0 +1,49 @@
---
- name: parser meta data
parser_metadata:
version: 1.0
command: show version
network_os: ios
- name: match version
pattern_match:
regex: "Version (\\S+),"
register: version
- name: match model
pattern_match:
regex: "^Cisco (.+) \\(revision"
register: model
- name: match image
pattern_match:
regex: "^System image file is (\\S+)"
register: image
- name: match uptime
pattern_match:
regex: "uptime is (.+)"
register: uptime
- name: match total memory
pattern_match:
regex: "with (\\S+)/(\\w*) bytes of memory"
register: total_mem
- name: match free memory
pattern_match:
regex: "with \\w*/(\\S+) bytes of memory"
register: free_mem
- name: export system facts to playbook
set_vars:
model: "{{ model.matches.0 }}"
image_file: "{{ image.matches.0 }}"
uptime: "{{ uptime.matches.0 }}"
version: "{{ version.matches.0 }}"
memory:
total: "{{ total_mem.matches.0 }}"
free: "{{ free_mem.matches.0 }}"
export: true
register: system_facts
extend: test.extension

View File

@@ -0,0 +1,79 @@
---
- name: "command_parser test for {{ ansible_network_os }} show_interface"
command_parser:
file: "{{ parser_path }}/show_interfaces.yaml"
content: "{{ lookup('file', '{{ output_path }}/show_interfaces.txt') }}"
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'interface_facts' in result.ansible_facts"
- "'GigabitEthernet0/0' in result.ansible_facts.interface_facts[0]"
- "'GigabitEthernet0/1' in result.ansible_facts.interface_facts[1]"
- "result.ansible_facts.interface_facts[0]['GigabitEthernet0/0']['config']['name'] == 'GigabitEthernet0/0'"
- "result.ansible_facts.interface_facts[0]['GigabitEthernet0/0']['config']['description'] == 'OOB Management'"
- "result.ansible_facts.interface_facts[1]['GigabitEthernet0/1']['config']['name'] == 'GigabitEthernet0/1'"
- "result.ansible_facts.interface_facts[1]['GigabitEthernet0/1']['config']['description'] == 'test-interface'"
- name: "command_parser test for {{ ansible_network_os }} show_version"
command_parser:
file: "{{ parser_path }}/show_version.yaml"
content: "{{ lookup('file', '{{ output_path }}/show_version.txt') }}"
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'system_facts' in result.ansible_facts"
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.system_facts['image_file']"
- "'IOSv' in result.ansible_facts.system_facts['model']"
- "'15.6(2)T' in result.ansible_facts.system_facts['version']"
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.system_facts['uptime']"
- "'62464K' in result.ansible_facts.system_facts['memory']['free']"
- "'460033K' in result.ansible_facts.system_facts['memory']['total']"
- name: "command_parser expansion test for {{ ansible_network_os }} show_version"
command_parser:
file: "{{ parser_path }}/show_version_expand.yaml"
content: "{{ lookup('file', '{{ output_path }}/show_version.txt') }}"
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'system_facts' in result.ansible_facts.test.extension"
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.test.extension.system_facts['image_file']"
- "'IOSv' in result.ansible_facts.test.extension.system_facts['model']"
- "'15.6(2)T' in result.ansible_facts.test.extension.system_facts['version']"
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.test.extension.system_facts['uptime']"
- "'62464K' in result.ansible_facts.test.extension.system_facts['memory']['free']"
- "'460033K' in result.ansible_facts.test.extension.system_facts['memory']['total']"
- name: "command_parser expansion test for {{ ansible_network_os }} show_interface"
command_parser:
file: "{{ parser_path }}/show_interfaces_expand.yaml"
content: "{{ lookup('file', '{{ output_path }}/show_interfaces.txt') }}"
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'system_facts' in result.ansible_facts.test.extension"
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.test.extension.system_facts['image_file']"
- "'IOSv' in result.ansible_facts.test.extension.system_facts['model']"
- "'15.6(2)T' in result.ansible_facts.test.extension.system_facts['version']"
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.test.extension.system_facts['uptime']"
- "'62464K' in result.ansible_facts.test.extension.system_facts['memory']['free']"
- "'460033K' in result.ansible_facts.test.extension.system_facts['memory']['total']"
- "'interface_facts' in result.ansible_facts.test.extension"
- "'GigabitEthernet0/0' in result.ansible_facts.test.extension.interface_facts[0]"
- "'GigabitEthernet0/1' in result.ansible_facts.test.extension.interface_facts[1]"
- "result.ansible_facts.test.extension.interface_facts[0]['GigabitEthernet0/0']['config']['name'] == 'GigabitEthernet0/0'"
- "result.ansible_facts.test.extension.interface_facts[0]['GigabitEthernet0/0']['config']['description'] == 'OOB Management'"
- "result.ansible_facts.test.extension.interface_facts[1]['GigabitEthernet0/1']['config']['name'] == 'GigabitEthernet0/1'"
- "result.ansible_facts.test.extension.interface_facts[1]['GigabitEthernet0/1']['config']['description'] == 'test-interface'"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/command_parser/command_parser')[0] }}"
- name: ios command_parser test
import_tasks: ios.yaml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- command_parser

View File

@@ -0,0 +1,12 @@
---
- set_fact:
test: string
- set_fact:
test_pass: "{{ lookup('config_template', 'pass.j2') }}"
test_fail: "{{ lookup('config_template', 'fail.j2') }}"
- assert:
that:
- "'test string' in test_pass"
- "'test string' not in test_fail"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/config_template/config_template')[0] }}"
- name: config_template test
import_tasks: config_template.yaml

View File

@@ -0,0 +1 @@
test {{ bad | default(omit) }}

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- config_template

View File

@@ -0,0 +1,35 @@
---
- name: interface_range Ethernet1-3
debug:
msg: "{{ 'Ethernet1-3' | interface_range }}"
register: result
- assert:
that:
- "'Ethernet1' in result.msg"
- "'Ethernet2' in result.msg"
- "'Ethernet3' in result.msg"
- name: interface_range Ethernet1,3-4,5
debug:
msg: "{{ 'Ethernet1,3-4,5' | interface_range }}"
register: result
- assert:
that:
- "'Ethernet1' in result.msg"
- "'Ethernet3' in result.msg"
- "'Ethernet4' in result.msg"
- "'Ethernet5' in result.msg"
- name: interface_range Ethernet1/3-5,8
debug:
msg: "{{ 'Ethernet1/3-5,8' | interface_range }}"
register: result
- assert:
that:
- "'Ethernet1/3' in result.msg"
- "'Ethernet1/4' in result.msg"
- "'Ethernet1/5' in result.msg"
- "'Ethernet1/8' in result.msg"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/interface_range/interface_range')[0] }}"
- name: interface_range test
import_tasks: interface_range.yaml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- interface_range

View File

@@ -0,0 +1,28 @@
---
- name: interface_split Ethernet1
debug:
msg: "{{ 'Ethernet1' | interface_split }}"
register: result
- assert:
that:
- "'1' in result.msg.index"
- "'Ethernet' in result.msg.name"
- name: interface_split Ethernet1 name
debug:
msg: "{{ 'Ethernet1' | interface_split('name') }}"
register: result
- assert:
that:
- "'Ethernet' in result.msg"
- name: interface_split Ethernet1 index
debug:
msg: "{{ 'Ethernet1' | interface_split('index') }}"
register: result
- assert:
that:
- "'1' in result.msg"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/interface_split/interface_split')[0] }}"
- name: interface_split test
import_tasks: interface_split.yaml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- interface_split

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,2 @@
---
template_path: "{{ role_path }}/templates"

View File

@@ -0,0 +1,14 @@
---
- name: generate config
debug:
msg: "{{ lookup('json_template', '{{ template_path }}/config.json') }}"
register: result
- assert:
that:
- "'GigabitEthernet0/0' in result.msg"
- "'config' in result['msg']['GigabitEthernet0/0']"
- "'Configured by Ansible' in result['msg']['GigabitEthernet0/0']['config']['description']"
- "result['msg']['GigabitEthernet0/0']['config']['mtu'] == '1500'"
- "'iGbE' in result['msg']['GigabitEthernet0/0']['config']['type']"
- "'GigabitEthernet0/0' in result['msg']['GigabitEthernet0/0']['config']['name']"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/json_template/json_template')[0] }}"
- name: json_template lookup plugin test
import_tasks: json_lookup.yaml

View File

@@ -0,0 +1,26 @@
{
"object": [
{
"object": [
{
"value": "GigabitEthernet0/0",
"key": "name"
},
{
"value": "iGbE",
"key": "type"
},
{
"value": "1500",
"key": "mtu"
},
{
"value": "Configured by Ansible",
"key": "description"
}
],
"key": "config"
}
],
"key": "GigabitEthernet0/0"
}

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- json_template

View File

@@ -0,0 +1,6 @@
---
want_file: "{{ role_path }}/files/{{ ansible_network_os }}/want.txt"
have_file: "{{ role_path }}/files/{{ ansible_network_os }}/have.txt"
want: "{{ lookup('file', want_file) }}"
have: "{{ lookup('file', have_file) }}"

View File

@@ -0,0 +1,137 @@
Building configuration...
Current configuration : 7250 bytes
!
! Last configuration change at 01:37:00 UTC Sun May 27 2018 by ansible
!
version 14.6
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname ios01
!
boot-start-marker
boot-end-marker
!
!
vrf definition Mgmt-intf
!
address-family ipv6
exit-address-family
!
address-family ipv6
exit-address-family
!
no logging buffered
no logging console
!
crypto pki trustpoint example.com
enrollment selfsigned
subject-name cn=samsung-ubuntu.actionmystique.net-Certificate
rsakeypair example.com
revocation-check none
!
crypto pki certificate chain example.com
username cisco privilege 15 secret 5 $1$u6jn$cZ5bnTL3wGFL3362agGH11
username ansible privilege 15 secret 5 $1$R503$jIYk.0/0/toCal0O08Yr70
username test
!
redundancy
!
no cdp run
!
interface Loopback0
description Loopback
ip address 192.168.255.2 255.255.255.255
!
interface GigabitEthernet0/0
description OOB Management
vrf forwarding Mgmt-intf
ip address 20.20.20.20 255.255.255.0
duplex full
speed auto
media-type rj45
!
interface GigabitEthernet0/1
description test-interface
mtu 2000
no ip address
ip ospf cost 12
duplex full
speed 1000
media-type rj45
!
router ospf 1
passive-interface Loopback0
network 172.31.0.8 0.0.0.3 area 0
network 172.31.0.12 0.0.0.3 area 0
network 172.31.0.24 0.0.0.3 area 0
network 192.168.255.2 0.0.0.0 area 0
!
router bgp 1
template peer-session IBGP
remote-as 65001
update-source Loopback0
exit-peer-session
!
bgp router-id 192.168.255.2
bgp log-neighbor-changes
neighbor 192.168.255.1 remote-as 1
neighbor 192.168.255.1 description iBGP peer nxos01
neighbor 192.168.255.1 update-source Loopback0
neighbor 192.168.255.4 remote-as 1
neighbor 192.168.255.4 description iBGP peer csr01
neighbor 192.168.255.4 update-source Loopback0
neighbor 192.168.255.5 remote-as 1
neighbor 192.168.255.5 description iBGP peer iosxr01
neighbor 192.168.255.5 update-source Loopback0
neighbor 192.168.255.6 remote-as 1
neighbor 192.168.255.6 description iBGP peer nxos02
neighbor 192.168.255.6 update-source Loopback0
neighbor 192.168.255.7 remote-as 1
neighbor 192.168.255.7 description iBGP peer csr02
neighbor 192.168.255.7 update-source Loopback0
neighbor 192.168.255.8 remote-as 1
neighbor 192.168.255.8 description iBGP peer ios02
neighbor 192.168.255.8 update-source Loopback0
neighbor 192.168.255.9 remote-as 1
neighbor 192.168.255.9 description iBGP peer iosxr02
neighbor 192.168.255.9 update-source Loopback0
neighbor 192.168.255.10 remote-as 1
neighbor 192.168.255.10 description iBGP peer nxos9k01
neighbor 192.168.255.10 update-source Loopback0
neighbor 192.168.255.11 remote-as 1
neighbor 192.168.255.11 description iBGP peer nxos9k02
neighbor 192.168.255.11 update-source Loopback0
!
address-family ipv4
network 192.168.255.2 mask 255.255.255.255
neighbor 192.168.255.1 activate
neighbor 192.168.255.4 activate
neighbor 192.168.255.5 activate
neighbor 192.168.255.6 activate
neighbor 192.168.255.7 activate
neighbor 192.168.255.8 activate
neighbor 192.168.255.9 activate
neighbor 192.168.255.10 activate
neighbor 192.168.255.11 activate
exit-address-family
!
ip forward-protocol nd
!
!
no ip http server
no ip http secure-server
ip route 192.168.10.0 255.255.255.0 192.168.1.1 2
ip route vrf Mgmt-intf 10.0.0.0 255.0.0.0 10.8.38.1
ip ssh version 2
ip ssh pubkey-chain
username ansible
key-hash ssh-rsa 23C70B25FA2899AB2B77CC5719DDE5CA
ip ssh server algorithm authentication publickey password
ip scp server enable
!
logging trap warnings
!

View File

@@ -0,0 +1,138 @@
Building configuration...
Current configuration : 7250 bytes
!
! Last configuration change at 01:37:00 UTC Sun May 27 2018 by ansible
!
version 15.6
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname ios01
!
boot-start-marker
boot-end-marker
!
!
vrf definition Mgmt-intf
!
address-family ipv4
exit-address-family
!
address-family ipv6
exit-address-family
!
no logging buffered
no logging console
!
crypto pki trustpoint example.com
enrollment selfsigned
subject-name cn=samsung-ubuntu.actionmystique.net-Certificate
revocation-check none
rsakeypair example.com
!
crypto pki certificate chain example.com
username cisco privilege 15 secret 5 $1$u6jn$cZ5bnTL3wGFL3362agGH11
username ansible privilege 15 secret 5 $1$R503$jIYk.0/0/toCal0O08Yr70
username test
!
redundancy
!
no cdp run
!
interface Loopback0
description Loopback
ip address 192.168.255.2 255.255.255.255
!
interface GigabitEthernet0/0
description OOB Management
vrf forwarding Mgmt-intf
ip address 20.20.20.20 255.255.255.0
duplex full
speed auto
media-type rj45
!
interface GigabitEthernet0/1
description test-interface
mtu 2000
no ip address
ip ospf cost 1
shutdown
duplex full
speed 1000
media-type rj45
!
router ospf 1
passive-interface Loopback0
network 172.31.0.8 0.0.0.3 area 0
network 172.31.0.12 0.0.0.3 area 0
network 172.31.0.24 0.0.0.3 area 0
network 192.168.255.2 0.0.0.0 area 0
!
router bgp 1
template peer-session IBGP
remote-as 65001
update-source Loopback0
exit-peer-session
!
bgp router-id 192.168.255.2
bgp log-neighbor-changes
neighbor 192.168.255.1 remote-as 1
neighbor 192.168.255.1 description iBGP peer nxos01
neighbor 192.168.255.1 update-source Loopback0
neighbor 192.168.255.4 remote-as 1
neighbor 192.168.255.4 description iBGP peer csr01
neighbor 192.168.255.4 update-source Loopback0
neighbor 192.168.255.5 remote-as 1
neighbor 192.168.255.5 description iBGP peer iosxr01
neighbor 192.168.255.5 update-source Loopback0
neighbor 192.168.255.6 remote-as 1
neighbor 192.168.255.6 description iBGP peer nxos02
neighbor 192.168.255.6 update-source Loopback0
neighbor 192.168.255.7 remote-as 1
neighbor 192.168.255.7 description iBGP peer csr02
neighbor 192.168.255.7 update-source Loopback0
neighbor 192.168.255.8 remote-as 1
neighbor 192.168.255.8 description iBGP peer ios02
neighbor 192.168.255.8 update-source Loopback0
neighbor 192.168.255.9 remote-as 1
neighbor 192.168.255.9 description iBGP peer iosxr02
neighbor 192.168.255.9 update-source Loopback0
neighbor 192.168.255.10 remote-as 1
neighbor 192.168.255.10 description iBGP peer nxos9k01
neighbor 192.168.255.10 update-source Loopback0
neighbor 192.168.255.11 remote-as 1
neighbor 192.168.255.11 description iBGP peer nxos9k02
neighbor 192.168.255.11 update-source Loopback0
!
address-family ipv4
network 192.168.255.2 mask 255.255.255.255
neighbor 192.168.255.1 activate
neighbor 192.168.255.4 activate
neighbor 192.168.255.5 activate
neighbor 192.168.255.6 activate
neighbor 192.168.255.7 activate
neighbor 192.168.255.8 activate
neighbor 192.168.255.9 activate
neighbor 192.168.255.10 activate
neighbor 192.168.255.11 activate
exit-address-family
!
ip forward-protocol nd
!
!
no ip http server
no ip http secure-server
ip route 192.168.10.0 255.255.255.0 192.168.1.1 2
ip route vrf Mgmt-intf 10.0.0.0 255.0.0.0 10.8.38.1
ip ssh version 2
ip ssh pubkey-chain
username ansible
key-hash ssh-rsa 23C70B25FA2899AB2B77CC5719DDE5CA
ip ssh server algorithm authentication publickey password
ip scp server enable
!
logging trap warnings
!

View File

@@ -0,0 +1,64 @@
---
- name: "config diff test for {{ ansible_network_os }} with default"
set_fact:
diff: "{{ lookup('netcfg_diff', want, have=have) }}"
vars:
- ansible_network_os: ios
- assert:
that:
- "'version 15.6' in diff"
- "'vrf definition Mgmt-intf\naddress-family ipv4' in diff"
- "'crypto pki trustpoint example.com\nrevocation-check none\nrsakeypair example.com' not in diff"
- "'no logging console' not in diff"
- name: "config diff test for {{ ansible_network_os }} with strict match"
set_fact:
diff: "{{ lookup('netcfg_diff', want, have=have, match='strict') }}"
vars:
- ansible_network_os: ios
- assert:
that:
- "'crypto pki trustpoint example.com\nrevocation-check none\nrsakeypair example.com' in diff"
- "'no logging console' not in diff"
- name: "config diff test for {{ ansible_network_os }} with exact match"
set_fact:
diff: "{{ lookup('netcfg_diff', want, have=have, match='exact') }}"
vars:
- ansible_network_os: ios
- assert:
that:
- "'no logging console' in diff"
- name: "config diff test for {{ ansible_network_os }} with block replace"
set_fact:
diff: "{{ lookup('netcfg_diff', want, have=have, replace='block') }}"
vars:
- ansible_network_os: ios
- assert:
that:
- "'interface GigabitEthernet0/1' in diff"
- "'description test-interface' in diff"
- "'mtu 2000' in diff"
- "'no ip address' in diff"
- "'ip ospf cost 1' in diff"
- "'shutdown' in diff"
- "'duplex full' in diff"
- "'speed 1000' in diff"
- "'media-type rj45' in diff"
- name: "config diff test for {{ ansible_network_os }} with block line"
set_fact:
diff: "{{ lookup('netcfg_diff', want, have=have, replace='line') }}"
vars:
- ansible_network_os: ios
- assert:
that:
- "'interface GigabitEthernet0/1' in diff"
- "'ip ospf cost 1' in diff"
- "'shutdown' in diff"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/netcfg_diff/netcfg_diff')[0] }}"
- name: ios config diff
import_tasks: ios.yaml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- netcfg_diff

View File

@@ -0,0 +1,13 @@
---
# main entrypoint
- import_playbook: command_parser/test.yml
- import_playbook: textfsm_parser/test.yml
- import_playbook: json_template/test.yml
- import_playbook: vlan_compress/test.yml
- import_playbook: vlan_expand/test.yml
- import_playbook: netcfg_diff/test.yml
- import_playbook: interface_range/test.yml
- import_playbook: interface_split/test.yml
- import_playbook: config_template/test.yml
- import_playbook: validate_role_spec/test.yml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- textfsm_parser

View File

@@ -0,0 +1,3 @@
---
parser_path: "{{ role_path }}/parser_templates/{{ ansible_network_os }}"
output_path: "{{ role_path }}/output/{{ ansible_network_os }}"

View File

@@ -0,0 +1,85 @@
GigabitEthernet0/0 is up, line protocol is up
Hardware is iGbE, address is 5e00.0002.0000 (bia 5e00.0002.0000)
Description: OOB Management
Internet address is 10.8.38.65/24
MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 253/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, Auto Speed, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 2000 bits/sec, 2 packets/sec
5 minute output rate 2000 bits/sec, 2 packets/sec
4973387 packets input, 816226566 bytes, 0 no buffer
Received 228869 broadcasts (0 IP multicasts)
461509 runts, 0 giants, 0 throttles
461509 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
3316083 packets output, 432440225 bytes, 0 underruns
0 output errors, 0 collisions, 3 interface resets
2303378 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
1 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
GigabitEthernet0/1 is up, line protocol is up
Hardware is iGbE, address is fa16.3e4e.c5e5 (bia fa16.3e4e.c5e5)
Description: test-interface
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, 1Gbps, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 4d07h, output 4d07h, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
89815 packets input, 27598643 bytes, 0 no buffer
Received 1 broadcasts (0 IP multicasts)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
404016 packets output, 27896846 bytes, 0 underruns
0 output errors, 0 collisions, 51 interface resets
89728 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
28 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
GigabitEthernet0/2 is up, line protocol is up
Hardware is iGbE, address is fa16.3eca.c938 (bia fa16.3eca.c938)
Description: test-interface-2
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full Duplex, 1Gbps, link type is auto, media type is RJ45
output flow-control is unsupported, input flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
Last input 3w1d, output 00:00:08, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
487240 packets input, 36339153 bytes, 0 no buffer
Received 8 broadcasts (0 IP multicasts)
183253 runts, 0 giants, 0 throttles
183253 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 0 multicast, 0 pause input
1115575 packets output, 73936479 bytes, 0 underruns
0 output errors, 0 collisions, 12 interface resets
0 unknown protocol drops
0 babbles, 0 late collision, 0 deferred
5 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out

View File

@@ -0,0 +1,44 @@
Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Tue 22-Mar-16 16:19 by prod_rel_team
ROM: Bootstrap program is IOSv
an-ios-01 uptime is 10 weeks, 6 days, 22 hours, 30 minutes
System returned to ROM by reload
System image file is "flash0:/vios-adventerprisek9-m"
Last reload reason: Unknown reason
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Cisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.
Processor board ID 92O0KON393UV5P77JRKZ5
4 Gigabit Ethernet interfaces
DRAM configuration is 72 bits wide with parity disabled.
256K bytes of non-volatile configuration memory.
2097152K bytes of ATA System CompactFlash 0 (Read/Write)
0K bytes of ATA CompactFlash 1 (Read/Write)
0K bytes of ATA CompactFlash 2 (Read/Write)
10080K bytes of ATA CompactFlash 3 (Read/Write)
Configuration register is 0x0

View File

@@ -0,0 +1,10 @@
Value Required name (\S+)
Value type ([\w ]+)
Value description (.*)
Value mtu (\d+)
Start
^${name} is up
^\s+Hardware is ${type} -> Continue
^\s+Description: ${description}
^\s+MTU ${mtu} bytes, -> Record

View File

@@ -0,0 +1,11 @@
Value version (\S+)
Value model (.+)
Value image (\S+)
Value uptime (.+)
Start
^.*Version ${version},
^.*uptime is ${uptime}
^System image file is ${image}
^Cisco ${model} \(revision -> Record

View File

@@ -0,0 +1,42 @@
---
- name: textfsm_parser test for {{ ansible_network_os }} show_interfaces
textfsm_parser:
file: "{{ parser_path }}/show_interfaces"
content: "{{ lookup('file', '{{ output_path }}/show_interfaces.txt') }}"
name: interface_facts
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'interface_facts' in result.ansible_facts"
- "result.ansible_facts.interface_facts[0]['name'] == 'GigabitEthernet0/0'"
- "result.ansible_facts.interface_facts[0]['mtu'] == '1500'"
- "result.ansible_facts.interface_facts[0]['description'] == 'OOB Management'"
- "result.ansible_facts.interface_facts[0]['type'] == 'iGbE'"
- "result.ansible_facts.interface_facts[1]['name'] == 'GigabitEthernet0/1'"
- "result.ansible_facts.interface_facts[1]['mtu'] == '2000'"
- "result.ansible_facts.interface_facts[1]['description'] == 'test-interface'"
- "result.ansible_facts.interface_facts[1]['type'] == 'iGbE'"
- "result.ansible_facts.interface_facts[2]['name'] == 'GigabitEthernet0/2'"
- "result.ansible_facts.interface_facts[2]['mtu'] == '2000'"
- "result.ansible_facts.interface_facts[2]['description'] == 'test-interface-2'"
- "result.ansible_facts.interface_facts[2]['type'] == 'iGbE'"
- name: textfsm_parser test for {{ ansible_network_os }} show_version
textfsm_parser:
file: "{{ parser_path }}/show_version"
content: "{{ lookup('file', '{{ output_path }}/show_version.txt') }}"
name: system_facts
register: result
vars:
- ansible_network_os: ios
- assert:
that:
- "'system_facts' in result.ansible_facts"
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.system_facts[0]['image']"
- "result.ansible_facts.system_facts[0]['model'] == 'IOSv'"
- "result.ansible_facts.system_facts[0]['uptime'] == '10 weeks, 6 days, 22 hours, 30 minutes'"
- "result.ansible_facts.system_facts[0]['version'] == '15.6(2)T'"

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/textfsm_parser/textfsm_parser')[0] }}"
- name: ios textfsm_parser test
import_tasks: ios.yaml

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- to_lines

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/to_lines/to_lines')[0] }}"
- name: to_lines test
import_tasks: to_lines.yaml

View File

@@ -0,0 +1,9 @@
---
- name: convert string to lines
set_fact:
test: "{{ 'test\nstring' | to_lines }}"
- assert:
that:
- test[0] == 'test'
- test[1] == 'string'

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- validate_role_spec

View File

@@ -0,0 +1,3 @@
---
mutually_exclusive:
- ['int_arg', 'missing_arg']

View File

@@ -0,0 +1,17 @@
---
argument_spec:
required_arg:
required: true
int_arg:
type: int
bool_arg:
type: bool
default_arg:
default: test
optional_arg:
mutually_exclusive:
- ['int_arg', 'missing_arg']
required_together:
- ['default_arg', 'optional_arg']

View File

@@ -0,0 +1,10 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/validate_role_spec/validate_role_spec')[0] }}"
- name: validate_role_spec test
import_tasks: validate_role_spec.yaml
- name: validate_role_spec failed test
import_tasks: validate_role_spec_failed.yaml

View File

@@ -0,0 +1,10 @@
---
- set_fact:
required_arg: value
int_arg: 10
bool_arg: true
optional_arg: value
- name: test validate_role_spec
validate_role_spec:
spec: test.yaml

View File

@@ -0,0 +1,11 @@
---
- name: test failed validate_role_spec
validate_role_spec:
spec: failedtest.yaml
ignore_errors: true
register: result
- assert:
that:
- "result.failed == true"
- "'missing required field in specification file: argument_spec' in result.msg"

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- vlan_compress

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/vlan_compress/vlan_compress')[0] }}"
- name: vlan_compress test
import_tasks: vlan_compress.yaml

View File

@@ -0,0 +1,36 @@
---
- name: vlan_compress single vlan
debug:
msg: "{{ [1] | vlan_compress }}"
register: result
- assert:
that:
- "'1' in result.msg"
- name: vlan_compress list of vlans1
debug:
msg: "{{ [1,2,3,4,5] | vlan_compress }}"
register: result
- assert:
that:
- "'1-5' in result.msg"
- name: vlan_compress list of vlans2
debug:
msg: "{{ [1,2,3,5] | vlan_compress }}"
register: result
- assert:
that:
- "'1-3,5' in result.msg"
- name: vlan_compress list of vlans3
debug:
msg: "{{ [1,2,4,5,6] | vlan_compress }}"
register: result
- assert:
that:
- "'1-2,4-6' in result.msg"

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
connection: local
roles:
- vlan_expand

View File

@@ -0,0 +1,7 @@
---
- name: import dependency role for test
import_role:
name: "{{ role_path.split('/tests/vlan_expand/vlan_expand')[0] }}"
- name: vlan_expand test
import_tasks: vlan_expand.yaml

View File

@@ -0,0 +1,35 @@
---
- name: vlan_expand single vlan
debug:
msg: "{{ 'vlan1' | vlan_expand }}"
register: result
- assert:
that:
- "'1' in result.msg"
- name: vlan_expand range of vlans1
debug:
msg: "{{ 'vlan1-5' | vlan_expand }}"
register: result
- assert:
that:
- "'1' in result.msg"
- "'2' in result.msg"
- "'3' in result.msg"
- "'4' in result.msg"
- "'5' in result.msg"
- name: vlan_expand range of vlans2
debug:
msg: "{{ 'vlan1,3-5,7' | vlan_expand }}"
register: result
- assert:
that:
- "'1' in result.msg"
- "'3' in result.msg"
- "'4' in result.msg"
- "'5' in result.msg"
- "'7' in result.msg"