diff --git a/changelogs/fragments/81628_galaxy_verify.yml b/changelogs/fragments/81628_galaxy_verify.yml new file mode 100644 index 00000000000..4aa76d1a43b --- /dev/null +++ b/changelogs/fragments/81628_galaxy_verify.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- galaxy - skip verification for unwanted Python compiled bytecode files (https://github.com/ansible/ansible/issues/81628). diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py index 24707b1e731..7553b8bcb1b 100644 --- a/lib/ansible/galaxy/collection/__init__.py +++ b/lib/ansible/galaxy/collection/__init__.py @@ -333,11 +333,18 @@ def verify_local_collection(local_collection, remote_collection, artifacts_manag os.path.join(b_collection_path, to_bytes(name, errors='surrogate_or_strict')) ) + b_ignore_patterns = [ + b'*.pyc', + ] + # Find any paths not in the FILES.json for root, dirs, files in os.walk(b_collection_path): for name in files: full_path = os.path.join(root, name) path = to_text(full_path[len(b_collection_path) + 1::], errors='surrogate_or_strict') + if any(fnmatch.fnmatch(full_path, b_pattern) for b_pattern in b_ignore_patterns): + display.v("Ignoring verification for %s" % full_path) + continue if full_path not in collection_files: modified_content.append( diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml index 0fe2f82d16f..2ad9c832172 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml @@ -270,6 +270,16 @@ path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_new_dir' state: directory +- name: create a new ignore directory + file: + path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/__pycache__' + state: directory + +- name: create a new ignore file + file: + path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/__pycache__/test.cpython-311.pyc' + state: touch + - name: verify modified collection locally-only (should fail) command: ansible-galaxy collection verify --offline ansible_test.verify register: verify @@ -282,6 +292,7 @@ - "'plugins/modules/test_module.py' in verify.stdout" - "'plugins/modules/test_new_file.py' in verify.stdout" - "'plugins/modules/test_new_dir' in verify.stdout" + - "'plugins/modules/__pycache__/test.cpython-311.pyc' not in verify.stdout" # TODO: add a test for offline Galaxy signature metadata