From a8d5358d7fb3d0d732d17c67f96e4681a50e8c8c Mon Sep 17 00:00:00 2001 From: Artur Molchanov Date: Thu, 15 Dec 2016 19:14:33 +0300 Subject: [PATCH] systemd module: Allow to stop activating service (#19383) * systemd module: Allow to stop activating service Allow to stop service with ActiveState=activating. * systemd: Fix incompatibility with Python 2.4 --- lib/ansible/modules/system/systemd.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 0b6c05351bc..e6b3d49c07a 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -239,6 +239,11 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing from ansible.module_utils._text import to_native + +def is_running_service(service_status): + return service_status['ActiveState'] in set(['active', 'activating']) + + # =========================================== # Main control flow @@ -382,13 +387,13 @@ def main(): if 'ActiveState' in result['status']: action = None if module.params['state'] == 'started': - if result['status']['ActiveState'] != 'active': + if not is_running_service(result['status']): action = 'start' elif module.params['state'] == 'stopped': - if result['status']['ActiveState'] == 'active': + if is_running_service(result['status']): action = 'stop' else: - if result['status']['ActiveState'] != 'active': + if not is_running_service(result['status']): action = 'start' else: action = module.params['state'][:-2] # remove 'ed' from restarted/reloaded