Knowledge Search


×
 

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

  [KB33400] Show Article Properties


Summary:

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.

 

Symptoms:
  • Automating some of the tasks performed on Juniper devices

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

 

Solution:

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 192.168.xx.xxx. 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
ansible 2.4.0.0
  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. 

 

Related Links: