From dd5bd733fc15f21eb6adbc6925e63affbf8ee759 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sat, 2 May 2026 20:09:54 +1200 Subject: [PATCH] apt_rpm: handle `update-kernel` rc=1 when no new kernel is available (#11949) * fix(apt_rpm): do not fail when update-kernel finds no new kernel update-kernel exits with rc=1 when the kernel is already at the latest version. Handle this case gracefully by checking for the known "There are no available kernels" message in stderr and returning changed=False instead of raising an error. Fixes #10055 * fix(apt_rpm): add changelog fragment for #11949 * Apply suggestion from review Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- .../11949-apt-rpm-update-kernel-no-new-kernel.yml | 2 ++ plugins/modules/apt_rpm.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11949-apt-rpm-update-kernel-no-new-kernel.yml diff --git a/changelogs/fragments/11949-apt-rpm-update-kernel-no-new-kernel.yml b/changelogs/fragments/11949-apt-rpm-update-kernel-no-new-kernel.yml new file mode 100644 index 0000000000..d7359f2e56 --- /dev/null +++ b/changelogs/fragments/11949-apt-rpm-update-kernel-no-new-kernel.yml @@ -0,0 +1,2 @@ +bugfixes: + - "apt_rpm - do not fail when ``update_kernel`` finds no new kernel available (https://github.com/ansible-collections/community.general/issues/10055, https://github.com/ansible-collections/community.general/pull/11949)." diff --git a/plugins/modules/apt_rpm.py b/plugins/modules/apt_rpm.py index b81c71c10c..0674793d14 100644 --- a/plugins/modules/apt_rpm.py +++ b/plugins/modules/apt_rpm.py @@ -144,6 +144,7 @@ APT_PATH = "/usr/bin/apt-get" RPM_PATH = "/usr/bin/rpm" APT_GET_ZERO = "\n0 upgraded, 0 newly installed" UPDATE_KERNEL_ZERO = "\nTry to install new kernel " +UPDATE_KERNEL_NO_NEW = "There are no available kernels" def local_rpm_package_name(path): @@ -233,8 +234,12 @@ def dist_upgrade(module): def update_kernel(module): rc, out, err = module.run_command( - ["/usr/sbin/update-kernel", "-y"], check_rc=True, environ_update={"LANGUAGE": "C", "LC_ALL": "C"} + ["/usr/sbin/update-kernel", "-y"], environ_update={"LANGUAGE": "C", "LC_ALL": "C"} ) + if rc != 0: + if UPDATE_KERNEL_NO_NEW in err: + return (False, out) + module.fail_json(msg=f"Error while updating kernel: {err or out}", rc=rc, stdout=out, stderr=err) return (UPDATE_KERNEL_ZERO not in out, out)