• Stars
    star
    302
  • Rank 138,030 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Junos modules for Ansible

Documentation Status

NOTE : The collection for Ansible is under development and changes are expected in the namespace/module implementation.
One may use it but it is recommended to currently use juniper.junos roles for professional implementation. Refer - https://github.com/Juniper/ansible-junos-stdlib/tree/roles for more info.

Juniper Ansible collection for Junos

The repo is under active development. If you take a clone, you are getting the latest, and perhaps not entirely stable code.

About

Juniper Networks supports Ansible for managing devices running the Junos operating system (Junos OS). This collection is hosted on the Ansible Galaxy website under the collection juniper.device. The juniper.device collection includes a set of Ansible modules that perform specific operational and configuration tasks on devices running Junos OS. These tasks include: installing and upgrading Junos OS, provisioning new Junos devices in the network, loading configuration changes, retrieving information, and resetting, rebooting, or shutting down managed devices. Please refer to the INSTALLATION section for instructions on installing this collection.

juniper.junos roles by Juniper Networks

Ansible galaxy is upgrading to collections and plans to deprecate roles in future. The master branch will now have juniper.device collection support. Juniper.junos roles have been moved to roles branch. For more information for roles, check: https://github.com/Juniper/ansible-junos-stdlib/tree/roles

Two Sets of Ansible Modules for Junos devices

Since Ansible version >= 2.1, Ansible also natively includes core modules for Junos. The Junos modules included in Ansible core have names which begin with the prefix junos_. The Junos modules included in this Juniper.device collection have names starting with module types. These two sets of Junos modules can coexist on the same Ansible control machine, and an Ansible play may invoke a module from either (or both) sets. Juniper Networks recommends using the modules in this collection when writing new playbooks that manage Junos devices.

Overview of Modules

This juniper.device collection includes the following modules:

  • command — Execute one or more CLI commands on a Junos device.
  • config — Manipulate the configuration of a Junos device.
  • facts — Retrieve facts from a Junos device.
  • jsnapy — Execute JSNAPy tests on a Junos device.
  • ping — Execute ping from a Junos device.
  • pmtud — Perform path MTU discovery from a Junos device to a destination.
  • rpc — Execute one or more NETCONF RPCs on a Junos device.
  • software — Install software on a Junos device.
  • srx_cluster — Add or remove SRX chassis cluster configuration.
  • system — Initiate operational actions on the Junos system.
  • table — Retrieve data from a Junos device using a PyEZ table/view.

PyEZ Version Requirement

For ansible collection juniper.device we will need to install junos-eznc(PyEZ) version 2.6.0 or higher.

Overview of Plugins

In addition to the modules listed above, a callback_plugin jsnapy is available for the module jsnapy.

The callback_plugin jsnapy helps to print on the screen additional information regarding jsnapy failed tests. For each failed test, a log will be printed after the RECAP of the playbook as shown in this example:

PLAY RECAP *********************************************************************
qfx10002-01                : ok=3    changed=0    unreachable=0    failed=1
qfx10002-02                : ok=3    changed=0    unreachable=0    failed=1
qfx5100-01                 : ok=1    changed=0    unreachable=0    failed=1

JSNAPy Results for: qfx10002-01 ************************************************
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "60021", "peer-state": "Idle", "peer-address": "192.168.0.1"}
Value of 'oper-status' not 'is-equal' at '//interface-information/physical-interface[normalize-space(admin-status)='up' and logical-interface/address-family/address-family-name ]' with {"oper-status": "down", "name": "et-0/0/18"}

JSNAPy Results for: qfx10002-02 ************************************************
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}

The jsnapy plugin is currently in Experimental stage, please provide feedback.

Callback plugins are not activated by default. They must be manually added to the Ansible configuration file under the [defaults] section using the variable callback_whitelist. Specifically, these lines should be added to the Ansible configuration file in order to allow the jsnapy callback plugin:

[defaults]
callback_whitelist = jsnapy

DOCUMENTATION

Official Juniper documentation (detailed information, including examples)

Ansible style documentation

INSTALLATION

You must have the DEPENDENCIES installed on your system. Check requirements.txt for the dependencies.

NOTICES

MacOS Mojave and newer

In MacOS Mojave and newer (>=10.14), ssh keys created with the system ssh-keygen are created using the newer 'OPENSSH' key format, even when specifying -t rsa during creation. This directly affects the usage of ssh keys, particularly when using the ssh_private_key_file. To create/convert/check keys, follow these steps:

  • Create a new RSA key: ssh-keygen -m PEM -t rsa -b 4096
  • Check existing keys: head -n1 ~/.ssh/some_private_key RSA keys will be -----BEGIN RSA PRIVATE KEY----- and OPENSSH keys will be -----BEGIN OPENSSH PRIVATE KEY-----
  • Convert an OPENSSH key to an RSA key: ssh-keygen -p -m PEM -f ~/.ssh/some_key

Ansible Galaxy collection

You can use the ansible-galaxy install command to install the latest version of the juniper.device collection.

sudo ansible-galaxy collection install juniper.device

You can also use the ansible-galaxy install command to install the latest development version of the junos role directly from GitHub.

sudo ansible-galaxy collection install git+https://github.com/Juniper/ansible-junos-stdlib.git#/ansible_collections/juniper/device

For more information visit - https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#specifying-the-location-to-search-for-collections

Git clone

For testing you can git clone this repo and run the env-setup script in the repo directory:

user@ansible-junos-stdlib> source env-setup

This will set your $ANSIBLE_LIBRARY variable to the repo location and the installed Ansible library path. For example:

$ echo $ANSIBLE_LIBRARY /home/jeremy/Ansible/ansible-junos-stdlib/library:/usr/share/ansible

Docker

To run this as a Docker container, which includes JSNAPy and PyEZ, simply pull it from the Docker hub and run it. The following will pull the latest image and run it in an interactive ash shell.

docker run -it --rm juniper/pyez-ansible

Although, you'll probably want to bind mount a host directory (perhaps the directory containing your playbooks and associated files). The following will bind mount the current working directory and start the ash shell.

docker run -it --rm -v $PWD:/project juniper/pyez-ansible

You can also use the container as an executable to run your playbooks. Let's assume we have a typical playbook structure as below:

example
|playbook.yml
|hosts
|-vars
|-templates
|-scripts

We can move to the example directory and run the playbook with the following command:

cd example/ docker run -it --rm -v $PWD:/playbooks juniper/pyez-ansible ansible-playbook -i hosts playbook.yml

You can pass any valid command string after the container name and it will be passed to Bash for execution.

You may have noticed that the base command is almost always the same. We can also use an alias to save some keystrokes.

alias pb-ansible="docker run -it --rm -v $PWD:/project juniper/pyez-ansible ansible-playbook" pb-ansible -i hosts playbook.yml

Extending the container with additional packages

It's possible to install additional OS (Alpine) packages, Python packages (via pip), and Ansible roles or collections at container instantiation. This can be done by passing in environment variables or bind mounting files.

OS Packages

Environment Variable: $APK Bind Mount: /extras/apk.txt File Format: list of valid Alpine packages, one per line Examples:

As an environment variable, where the file containing a list of packages is in the current directory.

docker run -it --rm -v $PWD:/project -e APK="apk.txt" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/apk.txt:/extras/apk.txt juniper/pyez-ansible

Python Packages

Environment Variable: $REQ Bind Mount: /extras/requirements.txt File Format: pip requirements file

Examples:

docker run -it --rm -v $PWD:/project -e REQ="requirements.txt" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/requirements.txt:/extras/requirements.txt juniper/pyez-ansible

Ansible Packages

Environment Variable: $ROLES Bind Mount: /extras/requirements.yml File Format: Ansible requirements file

NOTE: This works for collections as well as roles.

Examples:

docker run -it --rm -v $PWD:/project -e REQ="requirements.yml" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/requirements.txt:/extras/requirements.yml juniper/pyez-ansible

Example Playbook

This example outlines how to use Ansible to install or upgrade the software image on a device running Junos OS.

---
- name: Install Junos OS
  hosts: dc1
  collections:
    - juniper.device
  connection: local
  gather_facts: no
  vars:
    wait_time: 3600
    pkg_dir: /var/tmp/junos-install
    OS_version: 14.1R1.10
    OS_package: jinstall-14.1R1.10-domestic-signed.tgz
    log_dir: /var/log/ansible

  tasks:
    - name: Checking NETCONF connectivity
      wait_for: host={{ inventory_hostname }} port=830 timeout=5
    - name: Install Junos OS package
      software:
        reboot: yes
        version: "{{ OS_version }}"
        package: "{{ pkg_dir }}/{{ OS_package }}"
        logfile: "{{ log_dir }}/software.log"
      register: sw
      notify:
        - wait_reboot

  handlers:
    - name: wait_reboot
      wait_for: host={{ inventory_hostname }} port=830 timeout={{ wait_time }}
      when: not sw.check_mode

DEPENDENCIES

This modules requires the following to be installed on the Ansible control machine:

LICENSE

Apache 2.0

SUPPORT

Support for this juniper.device collection is provided by the community and Juniper Networks. If you have an issue with a module in the juniper.device collection, you may:

Support for the Junos modules included in Ansible core is provided by Ansible. If you have an issue with an Ansible core module you should open a Github issue against the Ansible project.

CONTRIBUTORS

Juniper Networks is actively contributing to and maintaining this repo. Please contact [email protected] for any queries.

Contributors: Nitin Kumar, Rahul Kumar, Stephen Steiner

Former Contributors:

Stacy W Smith, Jeremy Schulman, Rick Sherman, Damien Garros, David Gethings

More Repositories

1

py-junos-eznc

Python library for Junos automation
Python
666
star
2

contrail-controller

Contrail Controller
441
star
3

warp17

The Stateful Traffic Generator for Layer 1 to Layer 7
C
424
star
4

libxo

The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced.
C
287
star
5

go-netconf

NETCONF implementation in Go.
Go
253
star
6

open-nti

Open Network Telemetry Collector build with open source tools
Python
226
star
7

contrail-vrouter

Contrail Virtual Router
219
star
8

grpc-c

C implementation of gRPC layered on top of core library
C
218
star
9

open-register-design-tool

Tool to generate register RTL, models, and docs using SystemRDL or JSpec input
Verilog
170
star
10

wistar

Wistar is a tool to help create and share network topologies of virtual machines. It is designed to be light weight enough to run on a laptop or a small dedicated server.
JavaScript
154
star
11

junoscriptorium

A repository for scripts and script libraries
XSLT
151
star
12

vqfx10k-vagrant

Vagrant projects for vQFX10k
HTML
133
star
13

jsnapy

Python version of Junos Snapshot Administrator
Python
115
star
14

OpenClos

Python
114
star
15

yang

Junos Yang module
92
star
16

OpenJNPR-Container-vMX

OpenJNPR-Container-vMX
Shell
86
star
17

jxmlease

A Python module for converting XML to intelligent Python data structures, and converting Python data structures to XML.
Python
81
star
18

netconf-java

Java library for NETCONF
Java
72
star
19

junos-terraform

Go
70
star
20

py-junos-netconify

Junos console/bootstrap automation Python module
Python
65
star
21

net-netconf

A Ruby gem for NETCONF
Ruby
64
star
22

contrail-ansible-deployer

Ansible deployment for contrail
60
star
23

juise

juise is the JUNOS User Interface Script Environment, which allows users to develop, test, and execute script outside of JUNOS. For more information about juise, see:
C
53
star
24

libslax

libslax is a C implementation of the SLAX programming language, a dialect of XSLT that is more perl/C-like and easier to read/code/use. For additional information about SLAX, see
C
49
star
25

contrail-docker

Python
48
star
26

contrail

Contrail repo for core components (go based)
Go
44
star
27

contrail-kubernetes

OpenContrail Kubernetes integration
Go
44
star
28

healthbot-rules

Python
43
star
29

ruby-junos-ez-stdlib

A collection of Ruby classes to make Junos automation Easy. This is the "standard library" supported on all devices.
Ruby
35
star
30

YAPT

Yet Another Provisioning Tool
Python
31
star
31

vmx-docker-lwaftr

vMX Lightweight 4over6 Virtual Network Function with Snabb in a Docker Container
Python
30
star
32

contrail-installer

Install scripts for OpenContrail
Shell
30
star
33

jtimon

Junos Telemetry Interface (JTI) client
Go
30
star
34

nita

The parent repo of a framework to automatically build and test networks.
Shell
29
star
35

py-space-platform

Python library for Junos Space APIs
HTML
28
star
36

Intro-to-Using-Ansible-with-Junos-OS

Examples of Using Ansible with Junos Devices
27
star
37

puppet-netdev-stdlib-junos

Junos specific Provider code for "netdev_stdlib". Netdev is a vendor-neutral network abstraction framework developed by Juniper Networks and contributed freely to the DevOps community.
Ruby
25
star
38

vSRX-AWS

vSRX for Amazon Web Services
HCL
24
star
39

junos-snapshot-administrator

Shell
23
star
40

ebplane

eBPF based dataplane prototypes
C++
23
star
41

splitcopy

Improves file transfer rates when copying files to/from JUNOS/EVO/*nix hosts.
Python
22
star
42

docker-saltstack-junos

Dockerfile to create a working Saltstack container for Junos
Python
21
star
43

contrail-vnc

Contrail Virtual Network Controller
21
star
44

netconf-perl

Perl library for Netconf
Perl
20
star
45

meshrr

Hierarchical Route Reflectors and Route Servers @ Scale w/ Juniper cRPD & Kubernetes
Python
20
star
46

contrail-neutron-plugin

Opencontrail Neutron plugin + extensions
18
star
47

contrail-operator

Juniper K8s contrail operator
Go
18
star
48

JP4Agent

Juniper's P4 Runtime server implementation.
C++
18
star
49

telemetry

Juniper Telemetry models, augments and deviations
18
star
50

simple_reg_model

System verilog register model for uvm testbenches.
Perl
18
star
51

vijava

17
star
52

contrail-tripleo-heat-templates

Contrail tripleO heat templates
17
star
53

contrail-container-builder

Build contrail networking control components as micro-services
17
star
54

ruby-junos-ez-srx

Ruby libraries support Junos automation via NETCONF - "SRX library"
Ruby
16
star
55

contrail-web-core

Contrail web ui backend code
16
star
56

juniper-pytest

Juniper Pytest is an automation developer's toolkit. It provides everything an automation developer might need to automate configuration and validation of Juniper network equipment with Python and Ansible.
Makefile
16
star
57

topoviz

A network topology visualisation tool. Creates a force directed graph from the output of a JUNOS cli cmd
Perl
14
star
58

contrail-dev-env

Shell
14
star
59

jet-app-store

App store for Jet Apps
Python
14
star
60

terraform-provider-apstra

Apstra Terraform Provider
Go
14
star
61

netconf-call-home

C
14
star
62

contrail-heat

Openstack heat plugin and resources
13
star
63

contrail-charms

Juju charms for Contrail services.
13
star
64

yangc

YANG Compiler for JUNOS
C
12
star
65

contrail-server-manager

contrail server management
Python
12
star
66

contrail-sandesh

Contrail analytics IDL
C++
12
star
67

contrail-generateDS

Contrail XML schema code generator
Python
12
star
68

virtfs

VirtFS kernel driver for FreeBSD
C
12
star
69

nita-robot

Robot Framework test automation framework, part of the Juniper NITA solution
Python
12
star
70

contrail-kubernetes-docs

12
star
71

nita-webapp

nita-webapp, a lightweight django based webapp that orchestrates jenkins, ansible and robot, part of the Juniper NITA solution
JavaScript
12
star
72

contrail-test

12
star
73

contrail-packages

Build and packaging scripts for OpenContrail.
11
star
74

contrail-helm-deployer

Contrail Helm based deployment
11
star
75

contrail-fabric-utils

packaging
11
star
76

container-networking-ansible

Ansible provisioning for container networking solutions using OpenContrail
Python
11
star
77

contrail-dpdk

dpdk fork
C
11
star
78

lab-doc-convert

Shell
11
star
79

nita-yaml-to-excel

yaml2xls, a library and tools for converting between yaml files and MS excel, part of the Juniper NITA solution
Python
11
star
80

juniper-newrelic-plugin

New Relic Plugin for monitoring Juniper devices
Python
11
star
81

py-jnpr-wlc

EXPERIMENTAL: Python library for Juniper Wireless Lan Controller (WLC) product
Python
10
star
82

contrail-go-api

golang API bindings for OpenContrail
Go
10
star
83

contrail-web-controller

contrail web ui controller code
10
star
84

TelemetryInterface

9
star
85

vSRX-Azure

Python
9
star
86

contrail-packaging

Contrail VNC packaging
9
star
87

contrail-specs

Repository for docs and specs
9
star
88

vmx-heat-templates

vMX Heat templates
Python
8
star
89

healthbot-py-client

Python library that provides REST interface to the HealthBot server
Python
8
star
90

netlink-agent

netlink
C
8
star
91

junos-extension-toolkit

A repository to store JET IDL files
7
star
92

contrail-build

Contrail VNC build tools
7
star
93

jetez

Lightweight alternative to JET
Python
7
star
94

space-ansible-collection

space-ansible-collection
Python
7
star
95

nita-cli

Python
7
star
96

nita-ansible

Ansible, a radically simple IT automation engine, part of the Juniper NITA solution
Jinja
7
star
97

contrail-chef

Contrail Chef Cookbooks
HTML
6
star
98

amt-vlc

Module for the VLC media player leveraging AMT functionality
C
6
star
99

contrail-networking

Automate contrail config provisioning using GitOps based delivery
6
star
100

qfx5100-book

GitHub Repo for the O'Reilly QFX5100 book by Doug Hanks
Ruby
6
star