You can install Junos software upgrades using Python which can automate the process for you. We use Ansible to roll out upgrades to 16 routers at once (it’s very cool) but we wanted to test it using the Junos Py-EZ module first using virtual machines with Vagrant since that is how Ansible connects to Juniper devices. This python for Junos software upgrades on Vagrant virtual machines works on Windows and Linux (tested on Debian and Ubuntu)
Use Python for Batch Commands on Junos Vagrant Machines
First you need Python modules, if on Linux run these commands, on Windows install Python 2.7.10 and remember to add python.exe to the PATH during the installation wizard
sudo apt-get install libxml2-dev python-pip python-dev libxslt1-dev git -y
On both Linux and Windows, install the Junos-PyEZ module using pip. Windows users will need to install Git and make it part of their PATH environment.
pip install git+https://github.com/Juniper/py-junos-eznc
In the Vagrant Junos virtual machine device make sure netconf is enabled
vagrant ssh cli configure set system services netconf ssh
Create python Junos upgrade script
nano pythonjunosupgrade.py
Paste the code below and change your package to the path of your Junos upgrade. I got the Firefly perimeter upgrade from here. Change the host IP and the user and password in the dev object.
import os, sys, logging from jnpr.junos import Device from jnpr.junos.utils.sw import SW from jnpr.junos.exception import * host = '192.168.40.250' package = '/home/htpcguides/updatevsrx.tgz' remote_path = '/var/tmp' validate = True logfile = '/var/log/junos-pyez/install.log' dev = Device(host=host, user='root', passwd='passw0rd', port='830') print "Opening Junos device" dev.open() dev.timeout = 300 sw = SW(dev) print "Upgrading Junos software" utilupgrade = sw.install(package=package, remote_path=remote_path, validate=validate) #, progress=update_progress) print "Rebooting Junos device" sw.reboot() print "Closing connection" dev.close()