From ffcdc535368a0f22df38bb7e3439ddea027db211 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Sat, 11 Aug 2018 10:48:44 +0200 Subject: [PATCH] module_utils/vultr.py: Ensure comparison is accurate (#43298) In query_resource_by_key(), there is an equal comparison that is made to know if the object we are looking for is present. Due to type difference this comparison doesn't always retrieve true, even when it should. This is due to the fact that the value in r_data dict are of type unicode, while the other can be of type int, float,... . ``` >>> a = u'1' >>> type(a) >>> b = 1 >>> type(b) >>> a == b False >>> str(a) == str(b) True ``` Hence the values, for comparison purposes, are casted into strings. --- lib/ansible/module_utils/vultr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/vultr.py b/lib/ansible/module_utils/vultr.py index f52052502ca..18b7ccc1664 100644 --- a/lib/ansible/module_utils/vultr.py +++ b/lib/ansible/module_utils/vultr.py @@ -217,7 +217,7 @@ class Vultr: return {} for r_id, r_data in r_list.items(): - if r_data[key] == value: + if str(r_data[key]) == str(value): self.api_cache.update({ resource: r_data })