Juniper / vqfx10k-vagrant

Vagrant projects for vQFX10k
Apache License 2.0
136 stars 62 forks source link

Ansible ImportError: No module named jnpr.junos #5

Open siegster opened 7 years ago

siegster commented 7 years ago

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:

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@dgarros Can you please help.

dgarros commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

is it working after you setup the python interpreter?

halbritt commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

setting ansible_python_interpreter didn't seem to help.

halbritt commented 7 years ago

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 *********************************************************************