From 554285acb7f0830896066e46da148aa2679a5b1e Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 30 Oct 2019 22:19:08 +0200 Subject: [PATCH] Fix image detection in os_image openstack module (#63959) Currently first check was by checksum only, and if there are 2 images with the same checksum, but different names, this check fails with error: * Multiple matches found for None * To prevent this let's add more exact check in the beginning: 1. Firstly try to find by unique ID if it's given, most safe way. 2. Try to find by combination of name and checksum, not only checksum, it will drop duplicates with different name. 3. Try to find just by name, as most general approach. By going from most narrow to more general checks we can drop duplicates in more efficient manner. --- lib/ansible/modules/cloud/openstack/os_image.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_image.py b/lib/ansible/modules/cloud/openstack/os_image.py index 9a1d06d82ba..fc272a9fdf9 100644 --- a/lib/ansible/modules/cloud/openstack/os_image.py +++ b/lib/ansible/modules/cloud/openstack/os_image.py @@ -177,8 +177,10 @@ def main(): try: changed = False - if module.params['checksum']: - image = cloud.get_image(name_or_id=None, filters={'checksum': module.params['checksum']}) + if module.params['id']: + image = cloud.get_image(name_or_id=module.params['id']) + elif module.params['checksum']: + image = cloud.get_image(name_or_id=module.params['name'], filters={'checksum': module.params['checksum']}) else: image = cloud.get_image(name_or_id=module.params['name'])