From 32c5793de540892da7f63d164b3561d9816d2d31 Mon Sep 17 00:00:00 2001 From: Olaf Klischat Date: Mon, 9 Jan 2023 15:43:13 +0100 Subject: [PATCH] systemd: ignore errors in daemon_reload and daemon_reexec when running in a chroot or with $SYSTEMD_OFFLINE==1 (#79643) Signed-off-by: Olaf Klischat --- .../79643-fix-systemd-daemon-reload-in-chroot.yml | 2 ++ lib/ansible/modules/systemd_service.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/79643-fix-systemd-daemon-reload-in-chroot.yml diff --git a/changelogs/fragments/79643-fix-systemd-daemon-reload-in-chroot.yml b/changelogs/fragments/79643-fix-systemd-daemon-reload-in-chroot.yml new file mode 100644 index 00000000000..80307eb2c4f --- /dev/null +++ b/changelogs/fragments/79643-fix-systemd-daemon-reload-in-chroot.yml @@ -0,0 +1,2 @@ +bugfixes: + - systemd - daemon-reload and daemon-reexec ignore errors when running in a chroot (https://github.com/ansible/ansible/pull/79643) diff --git a/lib/ansible/modules/systemd_service.py b/lib/ansible/modules/systemd_service.py index 4cd323b9b55..cb3685f80d4 100644 --- a/lib/ansible/modules/systemd_service.py +++ b/lib/ansible/modules/systemd_service.py @@ -391,13 +391,19 @@ def main(): if module.params['daemon_reload'] and not module.check_mode: (rc, out, err) = module.run_command("%s daemon-reload" % (systemctl)) if rc != 0: - module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err)) + if is_chroot(module) or os.environ.get('SYSTEMD_OFFLINE') == '1': + module.warn('daemon-reload failed, but target is a chroot or systemd is offline. Continuing. Error was: %d / %s' % (rc, err)) + else: + module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err)) # Run daemon-reexec if module.params['daemon_reexec'] and not module.check_mode: (rc, out, err) = module.run_command("%s daemon-reexec" % (systemctl)) if rc != 0: - module.fail_json(msg='failure %d during daemon-reexec: %s' % (rc, err)) + if is_chroot(module) or os.environ.get('SYSTEMD_OFFLINE') == '1': + module.warn('daemon-reexec failed, but target is a chroot or systemd is offline. Continuing. Error was: %d / %s' % (rc, err)) + else: + module.fail_json(msg='failure %d during daemon-reexec: %s' % (rc, err)) if unit: found = False