From 89450214dca6dd3f268c0011a923f356f40d9aa4 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 20:10:26 +0200 Subject: [PATCH] [PR #11995/02b969ee backport][stable-12] cobbler_system: fix `KeyError` when adding new interface to existing system (#12003) cobbler_system: fix `KeyError` when adding new interface to existing system (#11995) * fix(cobbler_system): handle missing interface device on existing system When adding a new interface to an existing Cobbler system that does not yet have that interface defined, the module raised a KeyError. Use .get() with a fallback empty dict to safely handle that case. Also add a continue after the unknown-property warning to prevent a secondary KeyError on IFPROPS_MAPPING lookup. Fixes: #7007 * chore(cobbler_system): add changelog fragment for #11995 --------- (cherry picked from commit 02b969ee4d98000321a39923ba86485cdf749041) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- .../fragments/11995-cobbler-system-interface-keyerror.yml | 4 ++++ plugins/modules/cobbler_system.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11995-cobbler-system-interface-keyerror.yml 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 dac885f03d..27bffc4eeb 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