Repository: ansible/ansible

Issue:
service module does not honor check mode for solaris service_enable() method
##### ISSUE TYPE
 - Bug Report
##### ANSIBLE VERSION
```
all
```
##### COMPONENT NAME
service module

##### SUMMARY
The service module is not honoring check mode for the solaris method service_enable(). As a result, check mode runs do modify the system.
Please consider the following patch:

```patch
--- /var/lib/awx/venv/ansible/lib/python2.6/site-packages/ansible/modules/system/service.py	2017-04-12 09:56:33.000000000 -0400
+++ /var/lib/awx/venv/ansible/lib/python2.6/site-packages/ansible/modules/system/service.py.new	2017-09-05 15:10:12.891090473 -0400
@@ -1399,6 +1399,11 @@
         else:
             subcmd = "disable -s"
 
+        # Mark as changed and return if in check mode
+        if self.module.check_mode:
+            self.changed = True
+            return
+
         rc, stdout, stderr = self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name))
 
         if rc != 0:
```


Discussion:
@tgates81 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- issue type
- ansible version
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
@tgates81 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- issue type
- ansible version
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
@tgates81: This looks like an easy fix and you've already proposed a patch. Would you like to submit the PR?
Actually work blocks GitHub and I have limited time so it would be a hassle.
If you could take care of it yourself I'd appreciate it, otherwise it may
have to wait until the weekend.

Tyler

On Sep 5, 2017 9:36 PM, "Reid Wahl" <notifications@github.com> wrote:

> @tgates81 <https://github.com/tgates81>: This looks like an easy fix and
> you've already proposed a patch. Would you like to submit the PR?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/ansible/ansible/issues/29026#issuecomment-327349188>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AeM-bhnqQmWYMdXQuU2-utxdmYdOlEI1ks5sffc1gaJpZM4PNcD_>
> .
>


Resolving patch:
diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py
--- a/lib/ansible/modules/system/service.py
+++ b/lib/ansible/modules/system/service.py
@@ -1388,20 +1388,21 @@ def service_enable(self):
         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"
+        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:
+                subcmd = "disable -s"
 
-        rc, stdout, stderr = self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name))
+            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)
+            if rc != 0:
+                if stderr:
+                    self.module.fail_json(msg=stderr)
+                else:
+                    self.module.fail_json(msg=stdout)
 
         self.changed = True
 


Test patch: