diff --git a/module_utils/network_lsr/argument_validator.py b/module_utils/network_lsr/argument_validator.py index b5a9253..49a4419 100644 --- a/module_utils/network_lsr/argument_validator.py +++ b/module_utils/network_lsr/argument_validator.py @@ -350,6 +350,11 @@ class ArgValidatorDict(ArgValidator): def _validate_impl(self, value, name): result = {} seen_keys = set() + if value is None: + # Users might want to use jinja2 templates to set properties. As such, + # it's convenient to accept None as an alias for an empty dictionary + # e.g. setting like `"match": None` will be allowed by the role + return {} try: items = list(value.items()) except AttributeError: diff --git a/tests/unit/test_network_connections.py b/tests/unit/test_network_connections.py index 74f4d37..e32e20c 100644 --- a/tests/unit/test_network_connections.py +++ b/tests/unit/test_network_connections.py @@ -437,6 +437,7 @@ class TestValidator(unittest.TestCase): {"i": 5, "s": "s_default", "l": "6"}, v.validate({"i": "5", "l": "6"}) ) self.assertValidationError(v, {"k": 1}) + self.assertEqual(v.validate(None), {}) def test_validate_list(self):