From f414c77e176dddea5c6beb22386fafe471d3f80a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 2 Jun 2026 21:18:25 +0200 Subject: [PATCH] [PR #12168/1e3da48d backport][stable-13] portage: include msg in depclean failure fail_json (#12175) portage: include msg in depclean failure fail_json (#12168) cleanup_packages() called module.fail_json(cmd=, rc=, stdout=, stderr=) without the mandatory msg= argument. When the underlying emerge --depclean exited non-zero, AnsibleModule.fail_json() itself crashed with "AnsibleModule.fail_json() missing 1 required positional argument: 'msg'" before the real failure could reach the controller, leaving users with no diagnostic about why depclean actually failed. Same wording style as the sibling install_packages() failure branch ("Packages not installed."). (cherry picked from commit 1e3da48d706678d2c5b6897e2af8748c88db6f26) Co-authored-by: Yoann Gauthier-Colin --- changelogs/fragments/portage-depclean-fail_json-msg.yml | 2 ++ plugins/modules/portage.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/portage-depclean-fail_json-msg.yml diff --git a/changelogs/fragments/portage-depclean-fail_json-msg.yml b/changelogs/fragments/portage-depclean-fail_json-msg.yml new file mode 100644 index 0000000000..2f368c7877 --- /dev/null +++ b/changelogs/fragments/portage-depclean-fail_json-msg.yml @@ -0,0 +1,2 @@ +bugfixes: + - "portage - fix ``depclean: true`` crashing with ``AnsibleModule.fail_json() missing 1 required positional argument: 'msg'`` instead of reporting the actual emerge failure (https://github.com/ansible-collections/community.general/pull/12168)." diff --git a/plugins/modules/portage.py b/plugins/modules/portage.py index 29cbab4099..12f25b2f90 100644 --- a/plugins/modules/portage.py +++ b/plugins/modules/portage.py @@ -508,7 +508,13 @@ def cleanup_packages(module, packages): cmd, (rc, out, err) = run_emerge(module, packages, *args) if rc != 0: - module.fail_json(cmd=cmd, rc=rc, stdout=out, stderr=err) + module.fail_json( + cmd=cmd, + rc=rc, + stdout=out, + stderr=err, + msg="Packages not cleaned up.", + ) removed = 0 for line in out.splitlines():