From 3d3ce253f396ac0117659bf9f2cbc06c7377b508 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Thu, 3 Jun 2021 16:53:49 -0500 Subject: [PATCH] Change ANSIBLE_LIBRARY PATH processing (#3137) 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 --- src/molecule/provisioner/ansible.py | 11 +++++++---- src/molecule/test/unit/provisioner/test_ansible.py | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index 99a7173aa9..2baf6a8c6a 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -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() @@ -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): diff --git a/src/molecule/test/unit/provisioner/test_ansible.py b/src/molecule/test/unit/provisioner/test_ansible.py index 73ffe768a2..faaf7a9999 100644 --- a/src/molecule/test/unit/provisioner/test_ansible.py +++ b/src/molecule/test/unit/provisioner/test_ansible.py @@ -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): @@ -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):