diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py index 188e41b22dd..c3a1ff8e434 100644 --- a/lib/ansible/galaxy/collection/__init__.py +++ b/lib/ansible/galaxy/collection/__init__.py @@ -108,7 +108,7 @@ from ansible.galaxy.dependency_resolution import ( build_collection_dependency_resolver, ) from ansible.galaxy.dependency_resolution.dataclasses import ( - Candidate, Requirement, + Candidate, Requirement, _is_installed_collection_dir, ) from ansible.galaxy.dependency_resolution.errors import ( CollectionDependencyResolutionImpossible, @@ -606,6 +606,7 @@ def verify_collections( # NOTE: Verify local collection exists before # NOTE: downloading its source artifact from # NOTE: a galaxy server. + default_err = 'Collection %s is not installed in any of the collection paths.' % collection.fqcn for search_path in search_paths: b_search_path = to_bytes( os.path.join( @@ -616,13 +617,20 @@ def verify_collections( ) if not os.path.isdir(b_search_path): continue + if not _is_installed_collection_dir(b_search_path): + default_err = ( + "Collection %s does not have a MANIFEST.json. " + "A MANIFEST.json is expected if the collection has been built " + "and installed via ansible-galaxy" % collection.fqcn + ) + continue local_collection = Candidate.from_dir_path( b_search_path, artifacts_manager, ) break else: - raise AnsibleError(message='Collection %s is not installed in any of the collection paths.' % collection.fqcn) + raise AnsibleError(message=default_err) remote_collection = Candidate( collection.fqcn, diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml index eaef2f8227b..0047ca01d51 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml @@ -191,3 +191,33 @@ - assert: that: - "'Collection ansible_test.verify contains modified content in the following files:\nansible_test.verify\n MANIFEST.json' in verify.stdout" + +- name: remove the artifact metadata to test verifying a collection without it + file: + path: "{{ item }}" + state: absent + loop: + - "{{ manifest_path }}" + - "{{ file_manifest_path }}" + +- name: add some development metadata + copy: + content: | + namespace: 'ansible_test' + name: 'verify' + version: '2.0.0' + readme: 'README.md' + authors: ['Ansible'] + dest: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/galaxy.yml' + +- name: test we only verify collections containing a MANIFEST.json with the version on the server + command: ansible-galaxy collection verify ansible_test.verify:2.0.0 + register: verify + environment: + ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}' + ignore_errors: yes + +- assert: + that: + - verify.failed + - "'Collection ansible_test.verify does not have a MANIFEST.json' in verify.stderr"