-
Notifications
You must be signed in to change notification settings - Fork 4
02. How to use this repository
You will find at the root of the repository a JSNAPy presentation
This repository has ready-to-use JSNAPy content.
Khelil Sator / Juniper Networks
Please submit github issues and pull requests.
$ tree -d
.
├── group_vars
│ └── all
├── host_vars
│ ├── ex4300-17
│ ├── ex4300-18
│ └── ex4300-9
├── other_jsnapy_folder
│ ├── snapshots
│ └── testfiles
├── python
├── snapshots
└── testfiles
I am using this files naming convention:
- Ansible playbooks: pb.*.yml
- Jsnapy configuration files: cfg_file_*.yml
- Jsnapy test files: test_file_*.yml
- Jsnapy files for snap + snap + check workflow: cfg_file_check_*.yml and test_file_check_*.yml
- Jsnapy files for snap + snap + diff workflow: cfg_file_diff_*.yml and test_file_diff_*.yml
- Jsnapy files for snapcheck or snap + local snapcheck workflow: cfg_file_snapcheck_*.yml and test_file_snapcheck_*.yml
git clone https://github.com/ksator/Junos-verifications-automation-with-Jsnapy.git
cd junos-verifications-automation-with-jsnapy
The network topology used into this repository is composed of 3 junos devices (EX4300) connected in a triangle topology, configured with BGP.
The 3 junos devices are connected like this:
ex4300-17, ge-0/0/0 <-> ex4300-9, ge-0/0/0
ex4300-17, ge-0/0/1 <-> ex4300-18, ge-0/0/1
ex4300-18, ge-0/0/0 <-> ex4300-9, ge-0/0/1
The 3 devices are configured with BGP.
In order to configure your junos devices, you can use, for example, the following method with Ansible.
- Install the PyEZ dependencies
- Install the python libraries junos-eznc and jxmlease.
sudo pip install junos-eznc
sudo pip install jxmlease
- Install ansible
sudo pip install ansible==2.2.3.0
Another option would be to pull from docker hub a docker image that already has the requirements installed.
Configure netconf on the Junos devices:
set system services netconf ssh
commit
The default netconf port is 830. Make sure your server/laptop can access the devices management ip address on port 830.
The Ansible playbook to configure the devices is pb.yml. It is at the root of this repository.
The jinja2 template to build the junos configuration is template.j2. It is at the root of this repository.
The playbook pb.yml will render the template template.j2 using the devices variables and will push and commit the rendered junos configuration to the devices.
The rendered files are:
The inventory file we are using in this repository is hosts. It is at the root of the repository, so it is not at the default place. It also defines the ip address of each device with the variable junos_host. This variable is re-used in the playbooks.
There is an ansible.cfg file at the root of the repository. It refers to our inventory file (hosts): So, even if the inventory file is not /etc/ansible/hosts, there is no need to add -i hosts to your ansible-playbook commands.
group_vars and host_vars directories at the root of this repository define variables for hosts and for groups. The inventory file (hosts file at the root of the repository) also defines some variables. In order to see all variables for an hostname, you can run this command:
ansible -m debug -a "var=hostvars['hostname']" localhost
$ ansible-playbook pb.yml
PLAY [create junos configuration] **********************************************
TASK [Render BGP configuration for junos devices] ******************************
changed: [ex4300-9]
changed: [ex4300-18]
changed: [ex4300-17]
TASK [push bgp configuration on devices] ***************************************
changed: [ex4300-17]
changed: [ex4300-9]
changed: [ex4300-18]
PLAY [wait for peers to establish connections] *********************************
TASK [pause] *******************************************************************
Pausing for 25 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [localhost]
PLAY [check bgp states] ********************************************************
TASK [check bgp peers states] **************************************************
ok: [ex4300-9] => (item={u'peer_loopback': u'192.179.0.73', u'local_ip': u'192.168.0.5', u'peer_ip': u'192.168.0.4', u'interface': u'ge-0/0/0', u'asn': 110, u'name': u'ex4300-17'})
ok: [ex4300-18] => (item={u'peer_loopback': u'192.179.0.95', u'local_ip': u'192.168.0.0', u'peer_ip': u'192.168.0.1', u'interface': u'ge-0/0/0', u'asn': 109, u'name': u'ex4300-9'})
ok: [ex4300-17] => (item={u'peer_loopback': u'192.179.0.95', u'local_ip': u'192.168.0.4', u'peer_ip': u'192.168.0.5', u'interface': u'ge-0/0/0', u'asn': 109, u'name': u'ex4300-9'})
ok: [ex4300-17] => (item={u'peer_loopback': u'192.179.0.74', u'local_ip': u'192.168.0.2', u'peer_ip': u'192.168.0.3', u'interface': u'ge-0/0/1', u'asn': 104, u'name': u'ex4300-18'})
ok: [ex4300-18] => (item={u'peer_loopback': u'192.179.0.73', u'local_ip': u'192.168.0.3', u'peer_ip': u'192.168.0.2', u'interface': u'ge-0/0/1', u'asn': 110, u'name': u'ex4300-17'})
ok: [ex4300-9] => (item={u'peer_loopback': u'192.179.0.74', u'local_ip': u'192.168.0.1', u'peer_ip': u'192.168.0.0', u'interface': u'ge-0/0/1', u'asn': 104, u'name': u'ex4300-18'})
PLAY RECAP *********************************************************************
ex4300-17 : ok=3 changed=2 unreachable=0 failed=0
ex4300-18 : ok=3 changed=2 unreachable=0 failed=0
ex4300-9 : ok=3 changed=2 unreachable=0 failed=0
localhost : ok=1 changed=0 unreachable=0 failed=0
$ ls *.conf
ex4300-17.conf ex4300-18.conf ex4300-9.conf
If you prefer to build the virtual lab using Vagrant, you can refer to this repository