Repository: ansible/ansible

Issue:
Unable to manage services on systems relying on update-rc.d
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
The new `sysvinit` module in ansible 2.6 has a typo, which renders the system unable to detect the `update-rc.d` executable:

```python
    # locate binaries for service management
    paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
    binaries = ['chkconfig', ' update-rc.d', 'insserv', 'service']
```
Note the leading space in `' update-rc.d'`.  This breaks the ability to enable / disable services on systems relying on `update-rc.d` for it, and breaks idempotency for `state=enabled` on such systems with the service disabled, due to the implied `enabled=yes` in that case.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
sysvinit

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
  config file = None
  configured module search path = [u'/Users/dennis.conrad/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/dennis.conrad/github/sansible/elasticsearch/.venv_ansible2.6.1/lib/python2.7/site-packages/ansible
  executable location = /Users/dennis.conrad/github/sansible/elasticsearch/.venv_ansible2.6.1/bin/ansible
  python version = 2.7.14 (default, Jun 18 2018, 15:53:27) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### OS / ENVIRONMENT
All systems relying on `update-rc.d` to manage services.

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->
Install, but disable, a service on a system relying on `update-rc.d` to manage service (e.g. Ubuntu Bionic), then try to enable the service using the following snippet:

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Ensure Service XXX is Enabled
  become: yes
  service:
    name: XXX
    enabled: yes
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
The service is enabled, and the task returns `changed=true`.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
The service is *NOT* enabled, yet the task still returns `changed=true`.




Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/system/sysvinit.py b/lib/ansible/modules/system/sysvinit.py
--- a/lib/ansible/modules/system/sysvinit.py
+++ b/lib/ansible/modules/system/sysvinit.py
@@ -155,7 +155,7 @@ def main():
 
     # locate binaries for service management
     paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
-    binaries = ['chkconfig', ' update-rc.d', 'insserv', 'service']
+    binaries = ['chkconfig', 'update-rc.d', 'insserv', 'service']
 
     # Keeps track of the service status for various runlevels because we can
     # operate on multiple runlevels at once


Test patch: