summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2023-02-15 14:33:05 -0500
committerGitHub <noreply@github.com>2023-02-15 13:33:05 -0600
commitc0395c486a6a9e42f6d81eebfb99906acd665e3a (patch)
treed370aed4b81e2ed0ebe23e5ad6c263157d436535
parent65366f663de7d044f42ae6dd53368fd4c1f88b35 (diff)
downloadansible-c0395c486a6a9e42f6d81eebfb99906acd665e3a.tar.gz
fix installing collections from git repos that contain MANIFEST.json (#79808) (#79826)
* add null 'manifest' key to metadata for git repo collections containing MANIFEST.json changelog * set to Sentinel instead of None * Test installing a collection in a git repo that contains a MANIFEST.json * fix test * Update changelogs/fragments/ansible-galaxy-install-git-src-manifest.yml (cherry picked from commit 321848e98d9e565ee3f78c8c37ca879a8e3c55c1)
-rw-r--r--changelogs/fragments/ansible-galaxy-install-git-src-manifest.yml2
-rw-r--r--lib/ansible/galaxy/collection/__init__.py1
-rw-r--r--test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml1
-rw-r--r--test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml1
-rw-r--r--test/integration/targets/ansible-galaxy-collection-scm/tasks/test_manifest_metadata.yml55
5 files changed, 60 insertions, 0 deletions
diff --git a/changelogs/fragments/ansible-galaxy-install-git-src-manifest.yml b/changelogs/fragments/ansible-galaxy-install-git-src-manifest.yml
new file mode 100644
index 0000000000..684d978eef
--- /dev/null
+++ b/changelogs/fragments/ansible-galaxy-install-git-src-manifest.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - ansible-galaxy - fix installing collections in git repositories/directories which contain a MANIFEST.json file (https://github.com/ansible/ansible/issues/79796).
diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py
index 7f04052e89..7a144c0d05 100644
--- a/lib/ansible/galaxy/collection/__init__.py
+++ b/lib/ansible/galaxy/collection/__init__.py
@@ -1570,6 +1570,7 @@ def install_src(collection, b_collection_path, b_collection_output_path, artifac
if 'build_ignore' not in collection_meta: # installed collection, not src
# FIXME: optimize this? use a different process? copy instead of build?
collection_meta['build_ignore'] = []
+ collection_meta['manifest'] = Sentinel
collection_manifest = _build_manifest(**collection_meta)
file_manifest = _build_files_manifest(
b_collection_path,
diff --git a/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml b/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml
index e3dd5fb100..655a62f0d2 100644
--- a/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml
+++ b/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml
@@ -1,3 +1,4 @@
---
dependencies:
- setup_remote_tmp_dir
+- setup_gnutar
diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml
index 546c408395..dab599b15d 100644
--- a/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml
+++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml
@@ -30,6 +30,7 @@
- include_tasks: ./download.yml
- include_tasks: ./setup_collection_bad_version.yml
- include_tasks: ./test_invalid_version.yml
+ - include_tasks: ./test_manifest_metadata.yml
always:
diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/test_manifest_metadata.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/test_manifest_metadata.yml
new file mode 100644
index 0000000000..a01551cad8
--- /dev/null
+++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/test_manifest_metadata.yml
@@ -0,0 +1,55 @@
+- name: Test installing a collection from a git repo containing a MANIFEST.json
+ block:
+ - name: Create a temp directory for building the collection
+ file:
+ path: '{{ galaxy_dir }}/scratch'
+ state: directory
+
+ - name: Initialize a collection
+ command: 'ansible-galaxy collection init namespace_3.collection_1'
+ args:
+ chdir: '{{ galaxy_dir }}/scratch'
+
+ - name: Build the collection
+ command: 'ansible-galaxy collection build namespace_3/collection_1'
+ args:
+ chdir: '{{ galaxy_dir }}/scratch'
+
+ - name: Initialize git repository
+ command: 'git init {{ scm_path }}/namespace_3'
+
+ - name: Create the destination for the collection
+ file:
+ path: '{{ scm_path }}/namespace_3/collection_1'
+ state: directory
+
+ - name: Unarchive the collection in the git repo
+ unarchive:
+ dest: '{{ scm_path }}/namespace_3/collection_1'
+ src: '{{ galaxy_dir }}/scratch/namespace_3-collection_1-1.0.0.tar.gz'
+ remote_src: yes
+
+ - name: Commit the changes
+ shell: git add ./; git commit -m 'add collection'
+ args:
+ chdir: '{{ scm_path }}/namespace_3'
+
+ - name: Install the collection in the git repository
+ command: 'ansible-galaxy collection install git+file://{{ scm_path }}/namespace_3/.git'
+ register: result
+
+ - name: Assert the collection was installed successfully
+ assert:
+ that:
+ - '"namespace_3.collection_1:1.0.0 was installed successfully" in result.stdout_lines'
+
+ always:
+ - name: Clean up directories from test
+ file:
+ path: '{{ galaxy_dir }}/scratch'
+ state: absent
+ loop:
+ - '{{ galaxy_dir }}/scratch'
+ - '{{ scm_path }}/namespace_3'
+
+ - include_tasks: ./empty_installed_collections.yml