From fe840225fb9bdf28d0f17bb9df1566e3b2e0b37e Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Wed, 12 Aug 2015 13:00:53 +0000 Subject: [PATCH] Fix service.enable on: Debian 8, Ubuntu 15.04 Workaround for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=751638 See https://github.com/systemd/systemd/issues/937 --- lib/ansible/modules/system/service.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index bd0237b38ba..0d2ea25bf5d 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -503,10 +503,21 @@ class LinuxService(Service): 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,)) + def sysv_exists(name): + script = '/etc/init.d/' + name + return os.access(script, os.X_OK) + + def sysv_is_enabled(name): + return bool(glob.glob('/etc/rc?.d/S??' + name)) + + service_name = self.__systemd_unit + (rc, out, err) = self.execute_command("%s is-enabled %s" % (self.enable_cmd, service_name,)) if rc == 0: return True - return False + elif sysv_exists(service_name): + return sysv_is_enabled(service_name) + else: + return False def get_systemd_status_dict(self): (rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,))