diff --git a/plugins/module_utils/jsonpath.py b/plugins/module_utils/jsonpath.py index a4310683..e4bd7f13 100644 --- a/plugins/module_utils/jsonpath.py +++ b/plugins/module_utils/jsonpath.py @@ -44,7 +44,7 @@ def match_json_property(module, data, expr, value=None): def _match_value(buf, v): if isinstance(buf, list): # convert all values from bool to str and lowercase them - return v.lower() in [str(i).lower() for i in buf] + return all([str(i).lower() == v.lower() for i in buf]) elif isinstance(buf, str): return v.lower() == content.lower() elif isinstance(buf, bool): diff --git a/tests/unit/module_utils/test_jsonpath.py b/tests/unit/module_utils/test_jsonpath.py index aa7fb3f1..7aee8168 100644 --- a/tests/unit/module_utils/test_jsonpath.py +++ b/tests/unit/module_utils/test_jsonpath.py @@ -60,6 +60,24 @@ def test_boolean_value(): assert match_json_property(None, data, "containers[*].connected", "TRUE") assert match_json_property(None, data, "containers[0].poweron", "false") + data = { + "containers": [ + {"image": "nginx", "ready": False}, + {"image": "python", "ready": False}, + {"image": "mongo", "ready": True} + ] + } + assert not match_json_property(None, data, "containers[*].ready", "true") + + data = { + "containers": [ + {"image": "nginx", "ready": True}, + {"image": "python", "ready": True}, + {"image": "mongo", "ready": True} + ] + } + assert match_json_property(None, data, "containers[*].ready", "true") + def test_valid_expression(): data = dict(key="ansible", value="unit-test")