Support Support Downloads Knowledge Base Juniper Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[Remote Management] How to run Python, PyEZ and Ansible scripts quickly by using Juniper Docker images on Windows PC



Article ID: KB33400 KB Last Updated: 11 Apr 2019Version: 1.0

Network engineers who are involved with provisioning, monitoring, and maintenance of Juniper devices may come across PyEZ, Python, and Ansible for automation of tasks. In order to quickly set up an environment to run these scripts without having to worry about installing the prerequisite packages, pre-packaged images are available on the Docker Hub.

This article explains how to make quick use of the juniper/pyez-ansible image to run such scripts.


  • Automating some of the tasks performed on Juniper devices

  • Testing and running scripts quickly without worrying about installing dependency packages



On Windows PCs, there are two methods to install the Docker software.

  • Docker Toolbox (uses Oracle Virtual box)

  • Docker for Windows (uses Hyper-V). Docker Toolbox is recommended for first-time users or for systems that do not meet Hyper-V requirements. See "What to know before you install" for more information about prerequisites.

To make quick use of the juniper/pyez-ansible image to run the scripts, perform the following steps:
  1. Identify the Docker image necessary for your use case under Juniper on Docker Hub. In our case, we would use Juniper/pyez-ansible to cover most of the automation uses cases for network engineers working with Juniper devices. 
  2. Run the Docker software installed and you will be taken to the interactive shell.

                    ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/

Docker is configured to use the default machine with IP address For help getting started, refer to the docs at Docker Documentation.

  1. Start the interactive shell.
user@user MINGW64 /c/Program Files/Docker Toolbox
  1. Pull the image from the Docker Hub to the Docker Toolbox by using the following command:

$ docker run -it --rm juniper/pyez-ansible ash
  1. Check if the docker image is up and running.

user@user-T460 MINGW64 /c/Program Files/Docker Toolbox
$ docker ps
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
2d983659f9a6        juniper/pyez-ansible   "ash"               5 seconds ago       Up 4 seconds                            heuristic_ride
  1. When the image is started, you will be taken to the /project # prompt. Verify that Python, Ansible, and PyEZ are pre-installed. 

/project # python --version
Python 2.7.13
/project # python
Python 2.7.13 (default, Apr 20 2017, 12:13:37)
[GCC 6.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from jnpr.junos import Device
>>> exit()
/project # ansible --version
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Apr 20 2017, 12:13:37) [GCC 6.3.0]
  1. Now you can run the scripts that you have composed directly from the container. 


Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search