Troubleshoot Junos PyEZ (junos-eznc) Install Errors for Ansible Modules
Problem
Description
During execution of a juniper.device
module or a
Juniper.junos
module, the Ansible control node generates an
error that junos-eznc
is not installed. For example:
"msg": "junos-eznc (aka PyEZ) >= 2.6.0 is required for this module. However, junos-eznc does not appear to be currently installed. See https://github.com/Juniper/py-junos-eznc#installation for details on installing junos-eznc."
or
"msg": "junos-eznc is required but does not appear to be installed. It can be installed using `pip install junos-eznc`"
Cause
The Juniper Networks Ansible modules in the juniper.device
collection and Juniper.junos
role use the Junos PyEZ Python library
to perform operations on Junos devices. Ansible generates this error if the library
is not installed or if Ansible can’t locate the library. Ansible might fail to
locate the library, for example, if you install Ansible in a virtual environment or
under a Python installation in a non-standard system location and Ansible is
searching for the library in a different location like the default system
location.
Solution
Install Junos PyEZ on the Ansible control node and update any necessary environment variables. See https://github.com/Juniper/py-junos-eznc#installation for more information.
If you run Ansible using a Python installation in a virtual environment or a non-standard system location, you must:
-
Install Junos PyEZ under the desired Python installation (in the virtual environment or non-standard system location, as appropriate).
-
Specify the path to the Python interpreter—for example, by setting the
interpreter_python
variable in the Ansible configuration file or by defining theansible_python_interpreter
variable for the appropriate devices in the Ansible inventory file.# file ansible.cfg [defaults] interpreter_python = /home/user/MyProjects/Ansible/venv/bin/python ...
For more information, see Interpreter Discovery in the official Ansible documentation.
To verify that Junos PyEZ is successfully installed on the control node, launch the
Python interactive shell using the same Python installation that you use for Ansible
operations. Then import the jnpr.junos
package.
(venv) user@ansible-cn:~/MyProjects/Ansible$ python3 Python 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import jnpr.junos >>> jnpr.junos.__version__ '2.6.0'
If you successfully import the jnpr.junos
package and there is no
error message, then Junos PyEZ is installed on the Ansible control node. If you
still see the same error message when you execute the Ansible module, make sure you
have specified the correct location for the Python interpreter in your Ansible
environment.
You can verify the Python installation that Ansible uses by executing your
Ansible playbook with the -vvv
option and reviewing the log
messages.