From 19bffccd3675b095c5c1066e140a4d58674185f2 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Mon, 7 Dec 2020 18:03:12 -0500 Subject: [PATCH] [stable-2.10] systemd - fix issue with capbpf and newer kernel (#72337) (#72347) * [stable-2.10] systemd - fix issue with capbpf and newer kernel (#72337) A bug existed in systemd 245 that did not properly handle unknown kernel capabilities gracefully. This resulted in incomplete output when querying for the service status. It is possible to get service status by other means. This PR works around this issue by getting service status using other commands in the event of a failure due to this bug. (cherry picked from commit db84e2c989) Co-authored-by: Sam Doran * [stable-2.10] systemd - use list-unit-files rather than list-units (#72363) list-unit-files will return all files on the system. list-units omits those that are disabled. Co-authored-by: Ken Dreyer (cherry picked from commit d6115887fafcb0c7c97dc63f658aee9756291353) * systemd - account for templated unit files when searching for service (#72702) Related to issue #71528 and PR #72337 Co-authored-by: Martin Polden (cherry picked from commit a788ea0132cb423dfb28e02264584ae64e9a3b80) --- .../fragments/71528-systemd-capbpf-workaround.yml | 4 ++++ .../71528-systemd-improve-unit-searching.yml | 4 ++++ .../fragments/71528-systemd-list-unit-files.yml | 5 +++++ lib/ansible/modules/systemd.py | 13 +++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 changelogs/fragments/71528-systemd-capbpf-workaround.yml create mode 100644 changelogs/fragments/71528-systemd-improve-unit-searching.yml create mode 100644 changelogs/fragments/71528-systemd-list-unit-files.yml 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/changelogs/fragments/71528-systemd-improve-unit-searching.yml b/changelogs/fragments/71528-systemd-improve-unit-searching.yml new file mode 100644 index 00000000000..92e5228ff8e --- /dev/null +++ b/changelogs/fragments/71528-systemd-improve-unit-searching.yml @@ -0,0 +1,4 @@ +bugfixes: + - > + systemd - account for templated unit files using ``@`` when searching for + the unit file (https://github.com/ansible/ansible/pull/72347#issuecomment-730626228) diff --git a/changelogs/fragments/71528-systemd-list-unit-files.yml b/changelogs/fragments/71528-systemd-list-unit-files.yml new file mode 100644 index 00000000000..7b63f674a60 --- /dev/null +++ b/changelogs/fragments/71528-systemd-list-unit-files.yml @@ -0,0 +1,5 @@ +bugfixes: + - > + systemd - follow up fix to https://github.com/ansible/ansible/issues/72338 + to use ``list-unit-files`` rather than ``list-units`` in order to show + all units files on the system. diff --git a/lib/ansible/modules/systemd.py b/lib/ansible/modules/systemd.py index edebfc9de58..a0bf8057c6e 100644 --- a/lib/ansible/modules/systemd.py +++ b/lib/ansible/modules/systemd.py @@ -414,6 +414,19 @@ 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')) + + unit, sep, suffix = unit.partition('@') + unit_search = '{unit}{sep}*'.format(unit=unit, sep=sep) + (rc, out, err) = module.run_command("{systemctl} list-unit-files '{unit_search}'".format(systemctl=systemctl, unit_search=unit_search)) + 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 = [