Skip to content

Commit

Permalink
Change ANSIBLE_LIBRARY PATH processing (#3137)
Browse files Browse the repository at this point in the history
When the environment variable ANSIBLE_LIBRARY is used, molecule is
currently extending the path with the contents of the found variable,
however, this will cause problems as the system driven path will
conflict with a user defined path. To correct this issue the path
processing will now insert the user provided variable into the path.

Lanuch-Pad: https://bugs.launchpad.net/tripleo/+bug/1930757
Signed-off-by: Kevin Carter <kecarter@redhat.com>
  • Loading branch information
Kevin Carter authored Jun 3, 2021
1 parent 5407716 commit 3d3ce25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,13 @@ def _get_modules_directories(self):
Adds modules directory from molecule and its plugins.
"""
paths = [util.abs_path(os.path.join(self._get_plugin_directory(), "modules"))]
paths = list()
if os.environ.get("ANSIBLE_LIBRARY"):
paths = list(map(util.abs_path, os.environ["ANSIBLE_LIBRARY"].split(":")))

paths.append(
util.abs_path(os.path.join(self._get_plugin_directory(), "modules"))
)

for d in drivers():
p = d.modules_dir()
Expand All @@ -939,9 +945,6 @@ def _get_modules_directories(self):
]
)

if os.environ.get("ANSIBLE_LIBRARY"):
paths.extend(map(util.abs_path, os.environ["ANSIBLE_LIBRARY"].split(":")))

return paths

def _get_filter_plugin_directory(self):
Expand Down
6 changes: 3 additions & 3 deletions src/molecule/test/unit/provisioner/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def test_get_modules_directories_single_ansible_library(_instance, monkeypatch):
paths = _instance._get_modules_directories()

assert len(paths) == 6
assert paths[-1] == "/abs/path/lib"
assert paths[0] == "/abs/path/lib"


def test_get_modules_directories_multi_ansible_library(_instance, monkeypatch):
Expand All @@ -713,8 +713,8 @@ def test_get_modules_directories_multi_ansible_library(_instance, monkeypatch):
paths = _instance._get_modules_directories()

assert len(paths) == 7
assert paths[-2].endswith("relpath/lib")
assert paths[-1] == "/abs/path/lib"
assert paths[0].endswith("relpath/lib")
assert paths[1] == "/abs/path/lib"


def test_get_filter_plugin_directory(_instance):
Expand Down

0 comments on commit 3d3ce25

Please sign in to comment.