Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible ImportError: No module named jnpr.junos #5

Open
siegster opened this issue Oct 4, 2016 · 12 comments
Open

Ansible ImportError: No module named jnpr.junos #5

siegster opened this issue Oct 4, 2016 · 12 comments

Comments

@siegster
Copy link

siegster commented Oct 4, 2016

Hi,

I am having an issue with the Ansible portion, where it complains about hte jnpr.junos module. However, when doing a test straight from Python, the module can be accessed properly:

$ python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jnpr.junos
>>> jnpr.junos._version_
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '_version_'
>>> jnpr.junos.__version__
'2.0.1'

The Juniper.junos module for Ansible is also currently installed:

 sudo ansible-galaxy list
- Juniper.junos, 1.4.0

This is on a Mac OS X installation, with the following versions installed:

  • Ansible 2.1.1.0
  • Vagrant 1.8.5
  • VirtualBox 5.0.26r108824
  • vqfx10k-pfe-virtualbox-20160609.box
  • vqfx10k-re-virtualbox-15.1X53-D60.box

Might just very well be configuration related, but the VMs come up properly, yet I just cannot use the Ansible modules as they are called from the Vagrant File/current roles. Any help would be appreciated.

Thanks!

@vnitinv
Copy link

vnitinv commented Oct 4, 2016

are you using virtualenv. Try setting ansible_python_interpreter

Looks like it’s not able to find python (where PyEZ might be installed)

You might need to explicitly define where is python Using the variable “ansible_python_interpreter”
You can define it in the inventory file or any variable file

In the inventory, it will look like that

[all]
qfx junos_host=127.0.0.1 junos_port=2222

[all:vars]
ansible_ssh_username=xxxxx
ansible_ssh_password=xxxx
ansible_python_interpreter=/usr/local/bin/python

@siegster
Copy link
Author

siegster commented Oct 4, 2016

Hi,

Thanks for the quick reply. I am not using virtualenv and I have tried setting the ansible_python_interpreter, without any success. I have tried in the inventory, as mentioned above, as well as in the ansible.cfg file, but without any luck.

@vnitinv
Copy link

vnitinv commented Oct 20, 2016

@dgarros Can you please help.

@dgarros
Copy link
Contributor

dgarros commented Oct 21, 2016

Hi @siegster
Sorry for the late response,

Please can you check where is your python located with which python.
If you need to define ansible_python_interpreter, you can't do it in the inventory becaues it's dynamically generated by Vagrant and it's not supported to have it in the Ansible.cfg.
you need to add it in a variable file.

Also do you have this issue with all examples or with one specifically ?

Thanks
Damien

@halbritt
Copy link

halbritt commented Oct 21, 2016

Getting the same error with any environment that includes the jnpr.junos module. Error occurs when running the playbooks as well:

TASK [Deploy config to device ... please wait] *********************************
fatal: [vqfx1]: FAILED! => {"changed": false, "failed": true, "msg": "ImportError: No module named jnpr.junos"}

Set the python interpreter:

angstrom:light-2qfx halbritt$ which python
/usr/local/bin/python
angstrom:light-2qfx halbritt$ env | grep python
ANSIBLE_PYTHON_INTERPRETER=/usr/local/bin/python
angstrom:light-2qfx halbritt$`

@dgarros
Copy link
Contributor

dgarros commented Oct 21, 2016

is it working after you setup the python interpreter?

@halbritt
Copy link

Apologies, my comment was unclear as a result of order. The interpreter had been set when I got the error. Just now testing I'm testing jnpr.junos with the hello.py and it seems to be able to import jnpr.junos just fine.

@halbritt
Copy link

Running on Mac installed via pip:

angstrom:light-2qfx halbritt$ pip show junos-eznc | grep ^Version
Version: 2.0.1
Python 2.7.12
ansible 2.1.1.0

@dgarros
Copy link
Contributor

dgarros commented Oct 21, 2016

Please try to define ansible_python_interpreter in a variable file, for example in group_vars/all/python.yaml

Not sure if Env variables works with Vagrant

@halbritt
Copy link

I'll test that later. This is definitely related to how ansible is interpreting pythonpath vs. system default. Could also be an issue with homebrew installed python.

@halbritt
Copy link

setting ansible_python_interpreter didn't seem to help.

@halbritt
Copy link

halbritt commented Oct 22, 2016

Vagrant wasn't the culprit at all. I'm sure it had something to do with having python installed twice. I had used homebrew to install pip, which installed it's own version of python. When I pip installed junos-eznc, it was installed with that version of python that was also in the path.

which python was the homebrew installed version with junos-eznc installed. Ansible was using the system version regardless of which environment variable or shebang line I set.

Eventually, I fixed it by using homebrew to uninstall pip, ansible, and anything python related. Then I used easy_install to install pip against the system version. Then I pip installed junos-eznc and ansible. Following that process, I was able to get it to work.

The test case, well outside vagrant is just running the following:

angstrom:light-2qfx halbritt$ ansible-playbook pb.conf.all.commit.yaml

PLAY [Generate and Deploy Configuration] ***************************************

TASK [Build configuration] *****************************************************
ok: [vqfx2]
ok: [vqfx1]

TASK [Deploy config to device ... please wait] *********************************
changed: [vqfx1]
changed: [vqfx2]

PLAY RECAP *********************************************************************

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants