Tweak error checking for "enabled" code.

Based on input from @jarmani:
* A return value of 2 now means a service does not exist. Instead of
  trying to handle the different meanings of rc after running "status",
  just look at stderr to know if something failed.
* Skip looking at stdout to make the code cleaner. Any errors should
  turn up on stderr.
This commit is contained in:
Patrik Lundin 2014-08-31 11:58:37 +02:00 committed by Matt Clay
parent 32cb025b85
commit 25c3c03a11

View file

@ -1022,6 +1022,9 @@ class OpenBsdService(Service):
rc, stdout, stderr = self.execute_command("%s %s %s" % (self.enable_cmd, 'status', self.name))
if stderr:
self.module.fail_json(msg=stderr)
if self.enable:
action = "enable %s flags %s" % (self.name, self.arguments)
args = self.arguments
@ -1030,8 +1033,6 @@ class OpenBsdService(Service):
else:
action = "disable %s" % self.name
if rc == 1:
if stderr:
self.module.fail_json(msg=stderr)
return
if self.module.check_mode:
@ -1042,8 +1043,6 @@ class OpenBsdService(Service):
if rc != 0:
if stderr:
self.module.fail_json(msg=stderr)
elif stdout:
self.module.fail_json(msg=stdout)
else:
self.module.fail_json(msg="rcctl failed to modify service enablement")