# Merging module library paths

**URL:** <https://forum.ansible.com/t/merging-module-library-paths/14518>\
**Category:** Ansible Developer\
**Created:** [February 7, 2014, 12:08pm UTC](https://forum.ansible.com/t/merging-module-library-paths/14518 "2014-02-07T12:08:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [February 7, 2014, 12:08pm UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/1 "2014-02-07T12:08:33Z")

</div>

I run ansible from source, so my ANSIBLE\_LIBRARY is set using hacking/env-setup.

However, I would like to be able to add additional libraries outside of ansible, without having a different env-setup (or not running it at all) or always passing the location on the command line.

I see two ways of doing this:

- hacking/env-setup could read ANSIBLE\_CONFIG and and add the contents of library to the ANSIBLE\_LIBRARY path.
- lib/ansible/constants.py could combine the config and ANSIBLE\_LIBRARY values

There are probably other mechanisms (e.g. make the config file take precedence over the env variable, but that strikes me as worse)

Any thoughts as to better ways of doing this, or preferences over the two options (I think I like the second best, but open to other views).

Will

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [February 7, 2014, 6:20pm UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/2 "2014-02-07T18:20:19Z")

</div>

One of the paths looked at is library/ in relation to the playbook you are executing. If you don't have a library/ there already, you could symlink that to the alternate path you wish to pull modules from when executing that particular playbook.

-jlk

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [February 11, 2014, 1:33am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/3 "2014-02-11T01:33:11Z")

</div>

Thanks for that Jesse - it’s certainly something I hadn’t really considered.

In the end I went for combining the results of the configuration file and  
environment variable in  
[https://github.com/ansible/ansible/pull/5950](https://github.com/ansible/ansible/pull/5950)

So we’ll see how that turns out.

Will

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 11, 2014, 2:35am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/4 "2014-02-11T02:35:54Z")

</div>

Yeah got the pull request and asked for this thread and this thread is already here. Good deal 🙂

See some comments already on the PR. Generally, I’d suggest talking about something prior to issuing the PR.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 11, 2014, 2:39am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/5 "2014-02-11T02:39:47Z")

</div>

I would probably recommend just modifying the hacking/env-setup script to do what you want that is appropriate for your environment.

It’s basically there to enable development, not being a part of Ansible proper, so it doesn’t seem that core Ansible should change because of it, so much.

If an environment variable is set in Ansible, that overrides the file, and that’s pretty much standard across all the options.

A quick way around that would be to set PYTHONPATH and PATH, and then point ANSIBLE\_CFG at a configuration file that did more of what you wanted.

But I’m trying to find a non-code solution, obviously. Since this really hasn’t come up before.

The “./library → symlink to /opt/mystuff/library” is a workaround, but I agree it’s non-intuitive.

Perhaps there’s an option with setting an additional environment variable that would be more agreeable?

What if hacking/env-setup set something called ANSIBLE\_LIBRARY\_PREFIX\_PATH or something?

I don’t know, thinking out loud here…

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [February 11, 2014, 6:47am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/6 "2014-02-11T06:47:38Z")

</div>

Yes, I’m sure I would have quite enjoyed discussion on this before creating the PR, but I didn’t have much response other than Jesse’s useful tip, which I did give due consideration, but in the end decided to come up with a code-based solution and discuss afterwards.

I would accept a custom env-setup, except that it’s not just me that uses Ansible here, but all of our configuration management machines too (and yes, we run from near-bleeding edge because the patches we need aren’t necessarily in devel yet, let alone in release). Obviously I could fork env-setup internally but my general principle is that nothing should go into internal versions that wouldn’t be accepted upstream (as really, I’d much rather run from release!)

Given it’s called hacking/env-setup, a much lower-tech solution might actually be to just add any library path from any configured config file into env-setup (I think there are a couple of ansible defaults and then ANSIBLE\_CONFIG to check).

Are you suggesting setting ANSIBLE\_LIBRARY\_PREFIX\_PATH in env-setup instead of ANSIBLE\_LIBRARY? And then DEFAULT\_MODULE\_PATH becomes the combination of ANSIBLE\_LIBRARY\_PREFIX\_PATH and whatever is contained in (1) ANSIBLE\_LIBRARY or (2) config file library setting? That would probably be less gnarly than the combine\_config\_path (which as you say could be better documented)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 11, 2014, 12:45pm UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/7 "2014-02-11T12:45:04Z")

</div>

“Given it’s called hacking/env-setup, a much lower-tech solution might actually be to just add any library path from any configured config file into env-setup”

Maybe we could do that programatically? Load constants.py with a stub python script after setting PYTHON\_PATH and capture it in bash. (Basically make a quick hacking/get\_library\_path.py that env-setup could execute?)

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [February 12, 2014, 2:13am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/8 "2014-02-12T02:13:04Z")

</div>

Ok, brand new pull request submitted doing pretty much exactly that. Much simpler!

Will

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 12, 2014, 2:16am UTC](https://forum.ansible.com/t/merging-module-library-paths/14518/9 "2014-02-12T02:16:53Z")

</div>

EXCELLENT!
