Failure to enable a service now fails the task

Fixes: 8855
This commit is contained in:
Toshio Kuratomi 2014-09-18 12:39:54 -07:00
parent d5546d7a0a
commit 36083c3b90

View file

@ -647,7 +647,11 @@ class LinuxService(Service):
# committing the change is done in this conditional and then we # committing the change is done in this conditional and then we
# skip the boilerplate at the bottom of the method # skip the boilerplate at the bottom of the method
if self.changed: if self.changed:
write_to_override_file(override_file_name, override_state) try:
write_to_override_file(override_file_name, override_state)
except:
self.module.fail_json(msg='Could not modify override file')
return return
# #
@ -724,6 +728,9 @@ class LinuxService(Service):
if not self.changed: if not self.changed:
return return
#
# update-rc.d style
#
if self.enable_cmd.endswith("update-rc.d"): if self.enable_cmd.endswith("update-rc.d"):
if self.enable: if self.enable:
action = 'enable' action = 'enable'
@ -736,7 +743,10 @@ class LinuxService(Service):
(rc, out, err) = self.execute_command("%s %s defaults" \ (rc, out, err) = self.execute_command("%s %s defaults" \
% (self.enable_cmd, self.name)) % (self.enable_cmd, self.name))
if rc != 0: if rc != 0:
return (rc, out, err) if err:
self.module.fail_json(msg=err)
else:
self.module.fail_json(msg=out)
(rc, out, err) = self.execute_command("%s -n %s %s" \ (rc, out, err) = self.execute_command("%s -n %s %s" \
% (self.enable_cmd, self.name, action)) % (self.enable_cmd, self.name, action))
@ -761,7 +771,9 @@ class LinuxService(Service):
if not self.changed: if not self.changed:
return return
#
# If we've gotten to the end, the service needs to be updated # If we've gotten to the end, the service needs to be updated
#
self.changed = True self.changed = True
# we change argument order depending on real binary used: # we change argument order depending on real binary used:
@ -777,7 +789,14 @@ class LinuxService(Service):
if self.module.check_mode: if self.module.check_mode:
self.module.exit_json(changed=self.changed) self.module.exit_json(changed=self.changed)
return self.execute_command("%s %s %s" % args) (rc, out, err) = self.execute_command("%s %s %s" % args)
if rc != 0:
if err:
self.module.fail_json(msg=err)
else:
self.module.fail_json(msg=out)
return (rc, out, err)
def service_control(self): def service_control(self):
@ -900,7 +919,10 @@ class FreeBsdService(Service):
if self.rcconf_key is None: if self.rcconf_key is None:
self.module.fail_json(msg="unable to determine rcvar", stdout=stdout, stderr=stderr) self.module.fail_json(msg="unable to determine rcvar", stdout=stdout, stderr=stderr)
return self.service_enable_rcconf() try:
return self.service_enable_rcconf()
except:
self.module.fail_json(msg='unable to set rcvar')
def service_control(self): def service_control(self):