From df53297473a7948da97902c5fa7c17f6baedab3f Mon Sep 17 00:00:00 2001 From: rcordier Date: Thu, 12 Sep 2024 17:49:29 -0400 Subject: [PATCH] add: new option GALAXY_COLLECTIONS_INSTALL_PATH --- lib/ansible/cli/galaxy.py | 9 +++++++++ lib/ansible/config/base.yml | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 6ea3f708eec..c935ec5238b 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -708,6 +708,15 @@ class GalaxyCLI(CLI): return self.lazy_role_api.api def _get_default_collection_path(self): + + if isinstance(C.GALAXY_COLLECTIONS_INSTALL_PATH, list) and \ + len(C.GALAXY_COLLECTIONS_INSTALL_PATH) > 0 : + path_candidates = C.GALAXY_COLLECTIONS_INSTALL_PATH + for _path in path_candidates: + if os.path.isdir(_path): + return _path + return path_candidates[0] + return C.COLLECTIONS_PATHS[0] def _parse_requirements_file(self, requirements_file, allow_old_format=True, artifacts_manager=None, validate_signature_options=True): diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 445fd4540a1..80976b04cba 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -227,6 +227,22 @@ COLLECTIONS_PATHS: - key: collections_path section: defaults version_added: '2.10' +GALAXY_COLLECTIONS_INSTALL_PATH: + name: preferred collection install path + description: > + Preferred install path for collection. If empty or not set, fallback on first ``COLLECTIONS_PATHS`` path. + If one or more paths are provided, the first existing directory is selected. If no directory exists, it + will use the last one of the list. If the selected path is not in the ``COLLECTIONS_PATHS`` list, then + a warning is raised, unless ``GALAXY_COLLECTIONS_PATH_WARNING`` is set to ``false``. + default: null + type: pathspec + env: + - name: ANSIBLE_GALAXY_COLLECTIONS_INSTALL_PATH + version_added: '2.16' + ini: + - key: collections_install_path + section: defaults + version_added: '2.10' COLLECTIONS_ON_ANSIBLE_VERSION_MISMATCH: name: Defines behavior when loading a collection that does not support the current Ansible version description: