From 03d4b76b14a4522c3bbcbdfa23da7b0f93fc65b0 Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Thu, 28 Aug 2014 16:33:39 +0200 Subject: [PATCH] Check rc and print error message if any. It is probably good to use stdout before printing a generic error message as well. --- lib/ansible/modules/system/service.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index 7739fc8b00b..90363222ba5 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -1035,8 +1035,16 @@ class OpenBsdService(Service): if self.module.check_mode: self.module.exit_json(changed=True, msg="changing service enablement") - # XXX check rc ? rc, stdout, stderr = self.execute_command("%s %s" % (self.enable_cmd, action)) + + 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") + self.changed = True # ===========================================