From 3df2e15277947167f3eabb1669c8a875b160b0c6 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sat, 22 Jun 2013 11:43:38 +0200 Subject: [PATCH 1/2] Let update-rc.d set changed flag properly When update-rc.d is used to enable/disable service, the changed flag was always true (see #2189). This commit fixes that. Signed-off-by: martin f. krafft --- library/system/service | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/library/system/service b/library/system/service index 0a1ac6d7d3..54a386ebd1 100644 --- a/library/system/service +++ b/library/system/service @@ -547,6 +547,24 @@ class LinuxService(Service): if not self.enable: return + if self.enable_cmd.endswith("update-rc.d"): + action = 'enable' if self.enable else 'disable' + (rc, out, err) = self.execute_command("%s -n %s %s" \ + % (self.enable_cmd, self.name, action)) + self.changed = False + for line in out.splitlines(): + if line.startswith('rename'): + self.changed = True + break + + if self.module.check_mode: + self.module.exit_json(changed=changed) + + if not self.changed: + return + + return self.execute_command("%s %s %s" % (self.enable_cmd, self.name, action)) + # we change argument depending on real binary used: # - update-rc.d and systemctl wants enable/disable # - chkconfig wants on/off @@ -561,9 +579,7 @@ class LinuxService(Service): enable_disable = "disable" add_delete = "delete" - if self.enable_cmd.endswith("update-rc.d"): - args = (self.enable_cmd, self.name, enable_disable) - elif self.enable_cmd.endswith("rc-update"): + if self.enable_cmd.endswith("rc-update"): args = (self.enable_cmd, add_delete, self.name + " " + self.runlevel) elif self.enable_cmd.endswith("systemctl"): args = (self.enable_cmd, enable_disable, self.name + ".service") From 85b8538e0e0ad950f342424d7a18394614a7e02b Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 23 Jun 2013 09:19:27 +0200 Subject: [PATCH 2/2] Expand usage of Python 2.6 if statement Syntax like "'foo' if bar else 'baz'" is not supported by all Python versions targetted by Ansible. Hence we break it up. Signed-off-by: martin f. krafft --- library/system/service | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/system/service b/library/system/service index 54a386ebd1..e83bd19982 100644 --- a/library/system/service +++ b/library/system/service @@ -548,7 +548,10 @@ class LinuxService(Service): return if self.enable_cmd.endswith("update-rc.d"): - action = 'enable' if self.enable else 'disable' + if self.enable: + action = 'enable' + else: + action = 'disable' (rc, out, err) = self.execute_command("%s -n %s %s" \ % (self.enable_cmd, self.name, action)) self.changed = False