From 3e76a568f0b63a0faa336125448ee284549da9da Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Fri, 21 Apr 2023 07:29:10 -0500 Subject: [PATCH] Add GALAXY_COLLECTIONS_PATH_WARNINGS option. (#78487) * Add GALAXY_COLLECTIONS_PATH_WARNING option. This allows users to disable warnings from `ansible-galaxy collection install` about `--collections-path` missing from Ansible's configured collections_paths. (cherry picked from commit 734f38b2594692707d1fd3cbcfc8dc8a677f4ee3) --- .../fragments/78487-galaxy-collections-path-warnings.yml | 6 ++++++ lib/ansible/cli/galaxy.py | 2 +- lib/ansible/config/base.yml | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/78487-galaxy-collections-path-warnings.yml diff --git a/changelogs/fragments/78487-galaxy-collections-path-warnings.yml b/changelogs/fragments/78487-galaxy-collections-path-warnings.yml new file mode 100644 index 0000000000..4702e94f96 --- /dev/null +++ b/changelogs/fragments/78487-galaxy-collections-path-warnings.yml @@ -0,0 +1,6 @@ +--- +minor_changes: +- >- + Add ``GALAXY_COLLECTIONS_PATH_WARNING`` option to disable the warning + given by ``ansible-galaxy collection install`` when installing a collection + to a path that isn't in the configured collection paths. diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index d8a7c03756..3649be56f2 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -1401,7 +1401,7 @@ class GalaxyCLI(CLI): managed_paths = set(validate_collection_path(p) for p in C.COLLECTIONS_PATHS) read_req_paths = set(validate_collection_path(p) for p in AnsibleCollectionConfig.collection_paths) - unexpected_path = not any(p.startswith(path) for p in managed_paths) + unexpected_path = C.GALAXY_COLLECTIONS_PATH_WARNING and not any(p.startswith(path) for p in managed_paths) if unexpected_path and any(p.startswith(path) for p in read_req_paths): display.warning( f"The specified collections path '{path}' appears to be part of the pip Ansible package. " diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 052a8f0834..206deb76d2 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1366,6 +1366,15 @@ GALAXY_COLLECTION_SKELETON_IGNORE: ini: - {key: collection_skeleton_ignore, section: galaxy} type: list +GALAXY_COLLECTIONS_PATH_WARNING: + name: "ansible-galaxy collection install colections path warnings" + description: "whether ``ansible-galaxy collection install`` should warn about ``--collections-path`` missing from configured :ref:`collections_paths`" + default: true + type: bool + env: [{name: ANSIBLE_GALAXY_COLLECTIONS_PATH_WARNING}] + ini: + - {key: collections_path_warning, section: galaxy} + version_added: "2.16" # TODO: unused? #GALAXY_SCMS: # name: Galaxy SCMS -- 2.41.0