summaryrefslogtreecommitdiff
path: root/lib/ansible/galaxy
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2020-02-14 08:23:17 +1000
committerGitHub <noreply@github.com>2020-02-13 17:23:17 -0500
commit4881af2e7e0506ada0225fd764e874e20569d5b2 (patch)
tree61f4a33101393a283195bd0731a2bb7d23f9e453 /lib/ansible/galaxy
parent90898132e456ee1993db99a1531379f1b98ee915 (diff)
downloadansible-4881af2e7e0506ada0225fd764e874e20569d5b2.tar.gz
galaxy - Fix collection install dep resolver for bad versions (#67405)
* Also make sure version is a string and not an int/float
Diffstat (limited to 'lib/ansible/galaxy')
-rw-r--r--lib/ansible/galaxy/collection.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/ansible/galaxy/collection.py b/lib/ansible/galaxy/collection.py
index 24b13d97a1..4d7b327613 100644
--- a/lib/ansible/galaxy/collection.py
+++ b/lib/ansible/galaxy/collection.py
@@ -219,12 +219,15 @@ class CollectionRequirement:
requirement = req
op = operator.eq
- # In the case we are checking a new requirement on a base requirement (parent != None) we can't accept
- # version as '*' (unknown version) unless the requirement is also '*'.
- if parent and version == '*' and requirement != '*':
- break
- elif requirement == '*' or version == '*':
- continue
+ # In the case we are checking a new requirement on a base requirement (parent != None) we can't accept
+ # version as '*' (unknown version) unless the requirement is also '*'.
+ if parent and version == '*' and requirement != '*':
+ display.warning("Failed to validate the collection requirement '%s:%s' for %s when the existing "
+ "install does not have a version set, the collection may not work."
+ % (to_text(self), req, parent))
+ continue
+ elif requirement == '*' or version == '*':
+ continue
if not op(LooseVersion(version), LooseVersion(requirement)):
break
@@ -286,7 +289,13 @@ class CollectionRequirement:
manifest = info['manifest_file']['collection_info']
namespace = manifest['namespace']
name = manifest['name']
- version = manifest['version']
+ version = to_text(manifest['version'], errors='surrogate_or_strict')
+
+ if not hasattr(LooseVersion(version), 'version'):
+ display.warning("Collection at '%s' does not have a valid version set, falling back to '*'. Found "
+ "version: '%s'" % (to_text(b_path), version))
+ version = '*'
+
dependencies = manifest['dependencies']
else:
display.warning("Collection at '%s' does not have a MANIFEST.json file, cannot detect version."
@@ -877,7 +886,7 @@ def _get_collection_info(dep_map, existing_collections, collection, requirement,
existing = [c for c in existing_collections if to_text(c) == to_text(collection_info)]
if existing and not collection_info.force:
# Test that the installed collection fits the requirement
- existing[0].add_requirement(to_text(collection_info), requirement)
+ existing[0].add_requirement(parent, requirement)
collection_info = existing[0]
dep_map[to_text(collection_info)] = collection_info