Troubleshoot Junos PyEZ (junos-eznc) Install Errors for Ansible Modules
Problem
Description
During execution of a juniper.device module, the Ansible control
node generates an error that junos-eznc is not installed. For
example:
"msg": "junos-eznc is required but does not appear to be installed. It can be installed using `pip install junos-eznc`"
Cause
Many modules in the juniper.device collection 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, set the
interpreter_pythonvariable in the Ansible configuration file or define theansible_python_interpretervariable 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.12.3 (main, Nov 6 2025, 13:44:16) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import jnpr.junos >>> jnpr.junos.__version__ '2.7.5'
If you successfully import the jnpr.junos package, 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.