From 54d9d7805dc0a905fb9b2ad11746cfdc7ac03a53 Mon Sep 17 00:00:00 2001 From: Strahinja Kustudic Date: Thu, 8 Aug 2019 18:56:17 +0200 Subject: [PATCH] systemd module will now wait on deactivating state (#59471) If a service is in the 'deactivating' state running systemctl stop foo, would wait for the foo service to actually stop before it exits. The module didn't behave like that and it considered the deactivating state as if the service wasn't running. This change will align the module with the systemctl behaviour. --- .../fragments/59471-systemd-wait-while-deactivating.yaml | 2 ++ lib/ansible/modules/system/systemd.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/59471-systemd-wait-while-deactivating.yaml diff --git a/changelogs/fragments/59471-systemd-wait-while-deactivating.yaml b/changelogs/fragments/59471-systemd-wait-while-deactivating.yaml new file mode 100644 index 00000000000..455992dfb2a --- /dev/null +++ b/changelogs/fragments/59471-systemd-wait-while-deactivating.yaml @@ -0,0 +1,2 @@ +bugfixes: + - systemd - wait for a service which is in deactivating state when using ``state=stopped`` (https://github.com/ansible/ansible/pull/59471) diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 47424a4cef4..fd35ab69b2a 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -270,7 +270,11 @@ from ansible.module_utils._text import to_native def is_running_service(service_status): - return service_status['ActiveState'] in set(['active', 'activating']) + return service_status['ActiveState'] in set(['active', 'activating', 'deactivating']) + + +def is_deactivating_service(service_status): + return service_status['ActiveState'] in set(['deactivating']) def request_was_ignored(out): @@ -498,7 +502,7 @@ def main(): if not is_running_service(result['status']): action = 'start' elif module.params['state'] == 'stopped': - if is_running_service(result['status']): + if is_running_service(result['status']) or is_deactivating_service(result['status']): action = 'stop' else: if not is_running_service(result['status']):