Ansible Automation Example: JSNAPY PRE/POST Upgrade Validation

Overview

Ansible Automation Example: JSNAPY PRE/POST Upgrade Validation

N|Solid

Overview

This example will show how to validate the status of our firewall before and after a software upgrade. This project will leverage JSNAPY over NETCONF RPCs.

In addition to the Ansible playbok, this project also ships with additional tools to help you along your way. You will find a Dockerfile for running the project in an isolated environment, and a Makefile for those of us that hate typing out everything all the time.

🚀 Executing the playbook

This project provides two unique methods of executing the playbook:

  1. Docker
  2. Your own Python environment

🐳 Docker

With Invoke installed on your machine

If you have invoke installed, you can use these two commands to build the container and run the playbook.

  1. build the container image with
$ invoke container
  1. run the playbook to push the network configuration changes
$ invoke ansible

Without Invoke installed on your system

  1. build the container image with
$ docker build -t registry.gitlab.com/cremsburg/juniper-automation-container:jsnapy-ospf files/docker/
  1. run the playbook to push the network configuration changes
$ docker run -it --rm \
    -v $PWD/files/:/home/tmp/files \
    -v $PWD/files/:/home/tmp/files \
    -w /home/tmp/files/ansible/ \
    registry.gitlab.com/cremsburg/juniper-automation-container:jsnapy-ospf ansible-playbook pb.jsnapy.ospf.yaml

〰️ Notes about Docker

If you are unsure if Docker is installed on your computer, then it's probably safe to suggest that it's not. If you're interested in learning more about the product, I encourage you to read a few blogs on the topic. A personal recommendation would be Digital Ocean

Some of the goodies placed in the docker folder are not relevant to our use case with Python. Feel free to delete them as you see fit, I simply wanted to share with you my Docker build process for all Juniper automation projects (including those based on Ansible). The world is your oyster and I won't judge you on whatever direction you take.

🐍 Your own Python environment

I have included a Poetry file for anyone saavy enough to take advantage. For the uninitiated, Poetry helps replicate Python environments between users with a single file. You'll need to have Poetry installed on your machine, for most users that will be solved with pip install poetry.

This is optional, I will share the methods of going with Poetry or without

  1. install Python dependencies

1a. with Poetry

$ poetry install

1b. without Poetry

$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r files/docker/requirements.txt
  1. change into Ansible directory
$ cd files/ansible
  1. install official Ansible roles for Juniper devices
$ ansible-galaxy install juniper.junos
  1. run your Ansible playbook
$ ansible-playbook pb.jsnapy.ospf.yaml -i ../docker/inventory.yaml

⚠️ Running into an error about junos-eznc? ⚠️

There's an annoyance with Ansible and the way it interacts with your Python virtual environment. Do not let that frustrate you to the point that you ditch virtual environments altogether, instead use this quick technique to fix the problem.

From your terminal, find out the full path to Python within your virtual environment

$ which python
/home/cdot/.cache/pypoetry/virtualenvs/jsnapy-ospf-X7Chj_yD-py3.8/bin/python

Copy the output from your command and update the ansible.cfg file found in the same directory as the playbook. Do not update the ansible.cfg file in the root of this project, that won't accomplish anything.

add the following line to your ansible.cfg file, make sure to paste in the output of your clipboard rather than use my example

interpreter_python = /home/cdot/.cache/pypoetry/virtualenvs/jsnapy-ospf-X7Chj_yD-py3.8/bin/python

Sorry about that, one day Ansible will get it right. Until then, I recommend considering the Docker approach.

〰️ Notes about Python Virtual Environments

Similar to Docker, if you are unsure if you're using Python Virtual Environment features, it is safe to suggest that you're not. You are strongly recommended to using a Python Virtual Environment everywhere. You can really mess up your machine if you're too lazy and say "ehh, that seems like it's not important". It is. If it sounds like I'm speaking from experience, well I'll never admit to it.

If you're interested in learning more about setting up Virtual Environments, I encourage you to read a few blogs on the topic. A personal recommendation would be

📝 Dependencies

Refer to the Poetry Lock file located at poetry.lock for detailed descriptions on each package installed.

⚙️ How it works

Let's take a second to do a nice John Madden play-by-play by visiting the documentation in the files/docs/ directory.

Name Description
pb.jsnapy.ospf.rst Validate OSPF neighbors with JSNAPY

〰️ Just an FYI for Ansible AWX / Tower users

You'll note that there is an ansible.cfg file found in the root of the project's directory, as well as a folder roles/ to host the requirements.yml file.

The only purpose these serve is for Ansible Tower, which will look for these files when the project syncs from Gitlab/Github/Whatever, and Tower will auto-install the packages.

The ansible.cfg file will be the definitive for each Playbook (Template) execution, so super important to keep it here.

📸 Screenshot

pb.configure.yaml

You might also like...
A Python package to create, run, and post-process MODFLOW-based models.
A Python package to create, run, and post-process MODFLOW-based models.

Version 3.3.5 — release candidate Introduction FloPy includes support for MODFLOW 6, MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, and MODFLOW-2000. Other s

To propose and implement a multi-class classification approach to disaster assessment from the given data set of post-earthquake satellite imagery.
To propose and implement a multi-class classification approach to disaster assessment from the given data set of post-earthquake satellite imagery.

To propose and implement a multi-class classification approach to disaster assessment from the given data set of post-earthquake satellite imagery.

a spacial-temporal pattern detection system for home automation
a spacial-temporal pattern detection system for home automation

Argos a spacial-temporal pattern detection system for home automation. Based on OpenCV and Tensorflow, can run on raspberry pi and notify HomeAssistan

A generalized framework for prototyping full-stack cooperative driving automation applications under CARLA+SUMO.
A generalized framework for prototyping full-stack cooperative driving automation applications under CARLA+SUMO.

OpenCDA OpenCDA is a SIMULATION tool integrated with a prototype cooperative driving automation (CDA; see SAE J3216) pipeline as well as regular autom

Technical Indicators implemented in Python only using Numpy-Pandas as Magic  - Very Very Fast! Very tiny!  Stock Market Financial Technical Analysis Python library .  Quant Trading automation or cryptocoin exchange
Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! Very tiny! Stock Market Financial Technical Analysis Python library . Quant Trading automation or cryptocoin exchange

MyTT Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! to Stock Market Financial Technical Analysis Python

Worktory is a python library created with the single purpose of simplifying the inventory management of network automation scripts.

Worktory is a python library created with the single purpose of simplifying the inventory management of network automation scripts.

Privacy as Code for DSAR Orchestration: Privacy Request automation to fulfill GDPR, CCPA, and LGPD data subject requests.
Privacy as Code for DSAR Orchestration: Privacy Request automation to fulfill GDPR, CCPA, and LGPD data subject requests.

Meet Fidesops: Privacy as Code for DSAR Orchestration A part of the greater Fides ecosystem. ⚡ Overview Fidesops (fee-dez-äps, combination of the Lati

Flappy bird automation using Neuroevolution of Augmenting Topologies (NEAT) in Python
Flappy bird automation using Neuroevolution of Augmenting Topologies (NEAT) in Python

FlappyAI Flappy bird automation using Neuroevolution of Augmenting Topologies (NEAT) in Python Everything Used Genetic Algorithm especially NEAT conce

 YOLOv4-v3 Training Automation API for Linux
YOLOv4-v3 Training Automation API for Linux

This repository allows you to get started with training a state-of-the-art Deep Learning model with little to no configuration needed! You provide your labeled dataset or label your dataset using our BMW-LabelTool-Lite and you can start the training right away and monitor it in many different ways like TensorBoard or a custom REST API and GUI. NoCode training with YOLOv4 and YOLOV3 has never been so easy.

Owner
Calvin Remsburg
Calvin Remsburg
Neon-erc20-example - Example of creating SPL token and wrapping it with ERC20 interface in Neon EVM

Example of wrapping SPL token by ERC2-20 interface in Neon Requirements Install

null 7 Mar 28, 2022
Example-custom-ml-block-keras - Custom Keras ML block example for Edge Impulse

Custom Keras ML block example for Edge Impulse This repository is an example on

Edge Impulse 8 Nov 2, 2022
Python-kafka-reset-consumergroup-offset-example - Python Kafka reset consumergroup offset example

Python Kafka reset consumergroup offset example This is a simple example of how

Willi Carlsen 1 Feb 16, 2022
Codes to pre-train T5 (Text-to-Text Transfer Transformer) models pre-trained on Japanese web texts

t5-japanese Codes to pre-train T5 (Text-to-Text Transfer Transformer) models pre-trained on Japanese web texts. The following is a list of models that

Kimio Kuramitsu 1 Dec 13, 2021
PyTorch common framework to accelerate network implementation, training and validation

pytorch-framework PyTorch common framework to accelerate network implementation, training and validation. This framework is inspired by works from MML

Dongliang Cao 3 Dec 19, 2022
Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.

Core ML Tools Use coremltools to convert machine learning models from third-party libraries to the Core ML format. The Python package contains the sup

Apple 3k Jan 8, 2023
Code for our paper at ECCV 2020: Post-Training Piecewise Linear Quantization for Deep Neural Networks

PWLQ Updates 2020/07/16 - We are working on getting permission from our institution to release our source code. We will release it once we are granted

null 54 Dec 15, 2022
An Image compression simulator that uses Source Extractor and Monte Carlo methods to examine the post compressive effects different compression algorithms have.

ImageCompressionSimulation An Image compression simulator that uses Source Extractor and Monte Carlo methods to examine the post compressive effects o

James Park 1 Dec 11, 2021
Code implementation from my Medium blog post: [Transformers from Scratch in PyTorch]

transformer-from-scratch Code for my Medium blog post: Transformers from Scratch in PyTorch Note: This Transformer code does not include masked attent

Frank Odom 27 Dec 21, 2022