diff --git a/changelogs/fragments/71528-systemd-capbpf-workaround.yml b/changelogs/fragments/71528-systemd-capbpf-workaround.yml new file mode 100644 index 00000000000..bf7cff1aa3f --- /dev/null +++ b/changelogs/fragments/71528-systemd-capbpf-workaround.yml @@ -0,0 +1,4 @@ +bugfixes: + - > + systemd - work around bug with ``systemd`` 245 and 5.8 kernel that does not correctly + report service state (https://github.com/ansible/ansible/issues/71528) diff --git a/lib/ansible/modules/systemd.py b/lib/ansible/modules/systemd.py index 921b64477d1..8b95750f4b9 100644 --- a/lib/ansible/modules/systemd.py +++ b/lib/ansible/modules/systemd.py @@ -400,6 +400,17 @@ def main(): # Check for loading error if is_systemd and not is_masked and 'LoadError' in result['status']: module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError'])) + + # Workaround for https://github.com/ansible/ansible/issues/71528 + elif err and rc == 1 and 'Failed to parse bus message' in err: + result['status'] = parse_systemctl_show(to_native(out).split('\n')) + + (rc, out, err) = module.run_command("{systemctl} list-units '{unit}*'".format(systemctl=systemctl, unit=unit)) + is_systemd = unit in out + + (rc, out, err) = module.run_command("{systemctl} is-active '{unit}'".format(systemctl=systemctl, unit=unit)) + result['status']['ActiveState'] = out.rstrip('\n') + else: # list taken from man systemctl(1) for systemd 244 valid_enabled_states = [