# Update search path?

**URL:** <https://forum.ansible.com/t/update-search-path/26650>\
**Category:** Ansible Developer\
**Created:** [February 3, 2018, 12:33am UTC](https://forum.ansible.com/t/update-search-path/26650 "2018-02-03T00:33:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Demitri\_Swan](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@Demitri\_Swan](https://forum.ansible.com/u/Demitri_Swan)\
**Post date:** [February 3, 2018, 12:33am UTC](https://forum.ansible.com/t/update-search-path/26650/1 "2018-02-03T00:33:21Z")

</div>

I’m working on an Ansible module that will enable Mesos operators to easily update resource reservations within the mesos platform. I’ve got things unit tested and validated against a dev cluster. Unfortunately, when I install the ansible package locally, some path issues come up.

How can a update the search path at runtime for a module? I have a package under module\_utils that contains generated python code from protobuf files. In order for the generated code to work, the package search path must start at the module\_utils directory. Updating the search path in the **init**.py for this package works in the dev environment and under test, but not when installing ansible locally from my fork. Afterward, I’ve tried using pkg\_resources.working\_set.add\_entries, it does not seem to update the search path because the path is not found when I execute my module outside of the dev environment. Let me provide an example:

Base module\_utils directory:

lib/ansible/module\_utils/mesos

The generated python code in the mesos package must reference package like this:

import mesos.mesos\_pb2

In the dev environment, conditionally updating the sys.path to include the module\_utils directory does the trick, but not in other executing environments.

Is there a recommended method of updating the search path so it will work outside of the development environment? I’m using the generated python code to avoid having to deal with JSON as the Content-Type. the generated code generates classes that are type checked and makes working with the Mesos Operator API a lot more predictable.

My code can be found here: [https://github.com/miroswan/ansible](https://github.com/miroswan/ansible). Of course, it is subject to change over time.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Demitri\_Swan](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@Demitri\_Swan](https://forum.ansible.com/u/Demitri_Swan)\
**Post date:** [February 3, 2018, 5:51pm UTC](https://forum.ansible.com/t/update-search-path/26650/2 "2018-02-03T17:51:16Z")

</div>

Did some investigation. When the code is executed, it appears the bundled in a zip archive. I’ve did some inspection using this in the **init**.py for lib/ansible/module\_utils/mesos

z = os.path.abspath(os.path.join(os.path.dirname( **file** ), ‘…’, ‘…’, ‘…’))  
files = [item.filename for item in ZipFile(z).infolist()]  
raise Exception(files)

[‘ansible/ **init**.py’, ‘ansible/module\_utils/ **init**.py’, ‘ansible\_module\_mesos\_resource\_reservations.py’, ‘ansible/modu  
le\_utils/mesos/api.py’, ‘ansible/module\_utils/basic.py’, ‘ansible/module\_utils/mesos/ **init**.py’, ‘ansible/module\_utils/\_text.py’, ’  
ansible/module\_utils/parsing/convert\_bool.py’, ‘ansible/module\_utils/parsing/ **init**.py’, ‘ansible/module\_utils/pycompat24.py’, ‘ans  
ible/module\_utils/six/ **init**.py’, ‘sitecustomize.py’]

None of the sub-packages are showing up. This is after i’ve updated the pythonpath. Now to figure out why.
