From 5faa256178173d7e4cbbd66d08df518631b2515b Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 30 Jul 2025 11:08:12 -0400 Subject: [PATCH] ansible-galaxy, dont display internals (#85571) Also note broken test for invalid collection paths Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> --- changelogs/fragments/hide_proto.yml | 2 ++ lib/ansible/galaxy/collection/__init__.py | 10 ++++++++-- .../targets/ansible-galaxy-collection/tasks/list.yml | 7 +++++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/hide_proto.yml diff --git a/changelogs/fragments/hide_proto.yml b/changelogs/fragments/hide_proto.yml new file mode 100644 index 00000000000..6159156d047 --- /dev/null +++ b/changelogs/fragments/hide_proto.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-galaxy no longer shows the internal protomatter collection when listing. diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py index 38737468dcd..77e3870bdd2 100644 --- a/lib/ansible/galaxy/collection/__init__.py +++ b/lib/ansible/galaxy/collection/__init__.py @@ -84,6 +84,7 @@ if t.TYPE_CHECKING: FileManifestEntryType = t.Dict[FileMetaKeysType, t.Union[str, int, None]] FilesManifestType = t.Dict[t.Literal['files', 'format'], t.Union[t.List[FileManifestEntryType], int]] +import ansible import ansible.constants as C from ansible.errors import AnsibleError from ansible.galaxy.api import GalaxyAPI @@ -143,6 +144,8 @@ ModifiedContent = namedtuple('ModifiedContent', ['filename', 'expected', 'instal SIGNATURE_COUNT_RE = r"^(?P\+)?(?:(?P\d+)|(?Pall))$" +_ANSIBLE_PACKAGE_PATH = pathlib.Path(ansible.__file__).parent + @dataclass class ManifestControl: @@ -1429,9 +1432,12 @@ def find_existing_collections(path_filter, artifacts_manager, namespace_filter=N paths = set() for path in files('ansible_collections').glob('*/*/'): path = _normalize_collection_path(path) - if not path.is_dir(): + if path.is_relative_to(_ANSIBLE_PACKAGE_PATH): + # skip internal path, those collections are not for galaxy use + continue + elif not path.is_dir(): continue - if path_filter: + elif path_filter: for pf in path_filter: try: path.relative_to(_normalize_collection_path(pf)) diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/list.yml b/test/integration/targets/ansible-galaxy-collection/tasks/list.yml index 4e2569f7215..c0eeca8349c 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/list.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/list.yml @@ -155,9 +155,12 @@ environment: ANSIBLE_COLLECTIONS_PATH: "i_dont_exist" -- assert: +- name: Ensure we get the expected error + assert: that: - - "'{}' not in list_result_error.stdout" + # FIXME: This test is currently incorrect, but not a fix to do in this PR, proper test is the commented out one. + - "'{}' in list_result_error.stdout" + #- "'None of the provided paths were usable' in list_result_error.stderr" - name: install an artifact to the second collections path command: ansible-galaxy collection install namespace1.name1 -s galaxy_ng {{ galaxy_verbosity }} -p "{{ galaxy_dir }}/prod"