From dbc7444376a16bb1daee2bb8a870fe48f98b5b77 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 6 Sep 2017 20:16:58 -0400 Subject: [PATCH] fix check mode for solaris enable/disable (#29049) (cherry picked from commit 78040495921966180fd79145dd6182a6d891fdf2) --- lib/ansible/modules/system/service.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index 5cd3bb9c67..e0ac781616 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -1388,20 +1388,21 @@ class SunOSService(Service): elif (not self.enable) and (not startup_enabled): return - # Mark service as started or stopped (this will have the side effect of - # actually stopping or starting the service) - if self.enable: - subcmd = "enable -rs" - else: - subcmd = "disable -s" - - rc, stdout, stderr = self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name)) - - if rc != 0: - if stderr: - self.module.fail_json(msg=stderr) + if not self.module.check_mode: + # Mark service as started or stopped (this will have the side effect of + # actually stopping or starting the service) + if self.enable: + subcmd = "enable -rs" else: - self.module.fail_json(msg=stdout) + subcmd = "disable -s" + + rc, stdout, stderr = self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name)) + + if rc != 0: + if stderr: + self.module.fail_json(msg=stderr) + else: + self.module.fail_json(msg=stdout) self.changed = True