From bd84f654568c1c6d84ab09d0348275edb41dca0f Mon Sep 17 00:00:00 2001 From: hakril Date: Sat, 2 Aug 2025 07:50:21 -0700 Subject: [PATCH] Improve capabilities module by detecting /sbin/getcap error message and stop early with a meaningful error message (#10455) * modules/capabilities.py: fail & propagate if getcap command error * Fix comment spacing (pep8) * Add changelogs fragment for PR 10455 * Update changelogs/fragments/10455-capabilities-improve-error-detection.yml Co-authored-by: Felix Fontein --------- Co-authored-by: clement rouault Co-authored-by: Felix Fontein --- .../fragments/10455-capabilities-improve-error-detection.yml | 2 ++ plugins/modules/capabilities.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/10455-capabilities-improve-error-detection.yml diff --git a/changelogs/fragments/10455-capabilities-improve-error-detection.yml b/changelogs/fragments/10455-capabilities-improve-error-detection.yml new file mode 100644 index 0000000000..40337a424b --- /dev/null +++ b/changelogs/fragments/10455-capabilities-improve-error-detection.yml @@ -0,0 +1,2 @@ +bugfixes: + - capabilities - using invalid path (symlink/directory/...) returned unrelated and incoherent error messages (https://github.com/ansible-collections/community.general/issues/5649, https://github.com/ansible-collections/community.general/pull/10455). \ No newline at end of file diff --git a/plugins/modules/capabilities.py b/plugins/modules/capabilities.py index b3143df0a4..08bd2e85ff 100644 --- a/plugins/modules/capabilities.py +++ b/plugins/modules/capabilities.py @@ -123,6 +123,8 @@ class CapabilitiesModule(object): if ' =' in stdout: # process output of an older version of libcap caps = stdout.split(' =')[1].strip().split() + elif stdout.strip().endswith(")"): # '/foo (Error Message)' + self.module.fail_json(msg="Unable to get capabilities of %s" % path, stdout=stdout.strip(), stderr=stderr) else: # otherwise, we have a newer version here # see original commit message of cap/v0.2.40-18-g177cd41 in libcap.git