Python can't find a common python script that is in module_utils when running modules that use it

I’m developing several new network modules for Ansible 2.3. I have placed the common functions that are shared among these modules in a python script and put it in ./module_utils/cnos/cnos.py. “cnos” is our operating system name, hence the name cnos.

The modules that use this library import it via “import cnos” , however when they run, I get the following error:

[WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:

Traceback (most recent call last):

File “/tmp/ansible_G7YHg_/ansible_module_cnos_command.py”, line 157, in

main()

File “/tmp/ansible_G7YHg_/ansible_module_cnos_command.py”, line 131, in main

output = output + cnos.waitForDeviceResponse(“\n”, “>”, 2, remote_conn)

NameError: global name ‘cnos’ is not defined

This is rectified by setting the PYTHONPATH to this value: /usr/local/lib/python2.7/dist-packages/ansible-2.3.0-py2.7.egg/ansible/module_utils

I am working from the development branch and after I ‘make’ it I install ansible via:

python setup.py install

Will the requirement to set PYTHONPATH be eliminated when official RCs are created, or is there something I’m doing wrong here…

Thanks

You probably want to follow the running from source instructions, to avoid having to install things while working on them. You can run everything directly from the git clone:

http://docs.ansible.com/ansible/intro_installation.html#running-from-source

Thanks for that. Now if I want to have my QA team test this with an installation, can you point me to the directions on how they would go about that? I scanned the documentation and it was’t obvious to me.

I found the info on how to make debs and rpms. I tried to do a build with ‘make deb’, but ran into an issue that I’ll put in a separate post…