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 10c9e42f253..0f652db94ed 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -272,6 +272,10 @@ def is_running_service(service_status): return service_status['ActiveState'] in set(['active', 'activating']) +def is_deactivating_service(service_status): + return service_status['ActiveState'] in set(['deactivating']) + + def request_was_ignored(out): return '=' not in out and 'ignoring request' in out @@ -492,7 +496,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']):