From 90f5a23f34a6c4cd6c1804129f01b58a0e4f1874 Mon Sep 17 00:00:00 2001 From: Jon Hadfield Date: Sun, 8 Feb 2015 17:02:37 +0000 Subject: [PATCH] use is-enabled to check systemd service status. --- lib/ansible/modules/system/service.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index a1abde15333..c712c43ce9f 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -482,6 +482,12 @@ class LinuxService(Service): if location.get('initctl', False): self.svc_initctl = location['initctl'] + def get_systemd_service_enabled(self): + (rc, out, err) = self.execute_command("%s is-enabled %s" % (self.enable_cmd, self.__systemd_unit,)) + if rc == 0: + return True + return False + def get_systemd_status_dict(self): (rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,)) if rc != 0: @@ -696,12 +702,11 @@ class LinuxService(Service): action = 'disable' # Check if we're already in the correct state - d = self.get_systemd_status_dict() - if "UnitFileState" in d: - if self.enable and d["UnitFileState"] == "enabled": - self.changed = False - elif not self.enable and d["UnitFileState"] == "disabled": - self.changed = False + service_enabled = self.get_systemd_service_enabled() + if self.enable and service_enabled: + self.changed = False + elif not self.enable and not service_enabled: + self.changed = False elif not self.enable: self.changed = False