diff --git a/changelogs/fragments/11995-cobbler-system-interface-keyerror.yml b/changelogs/fragments/11995-cobbler-system-interface-keyerror.yml new file mode 100644 index 0000000000..0e93530a98 --- /dev/null +++ b/changelogs/fragments/11995-cobbler-system-interface-keyerror.yml @@ -0,0 +1,4 @@ +bugfixes: + - cobbler_system - fix ``KeyError`` when adding a new interface to an existing system that does not yet have it defined + (https://github.com/ansible-collections/community.general/issues/7007, + https://github.com/ansible-collections/community.general/pull/11995). diff --git a/plugins/modules/cobbler_system.py b/plugins/modules/cobbler_system.py index 25eb8aa72d..8070755281 100644 --- a/plugins/modules/cobbler_system.py +++ b/plugins/modules/cobbler_system.py @@ -298,7 +298,8 @@ def main(): continue if key not in IFPROPS_MAPPING: module.warn(f"Property '{key}' is not a valid system property.") - if not system or system["interfaces"][device][IFPROPS_MAPPING[key]] != value: + continue + if not system or system["interfaces"].get(device, {}).get(IFPROPS_MAPPING[key]) != value: result["changed"] = True interface_properties[f"{key}-{device}"] = value