Repository: ansible/ansible

Issue:
Fix traceback in service module when svc_cmd is None (2nd fix)
When service module is used on unsupported Linux system where init script is used directly, LinuxService.svc_cmd is None so .endswith() fails.

This extends fix from e2f20db53481128553d876109d5fbdab9f43dd5b also for state=restarted.

Fixes issue #3533

Running against Debian Lenny server:

```
$ ansible webserver.local -i webserver.local, -u root -m service -a 'name=apache2 state=restarted'
webserver.local | FAILED => failed to parse: Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 2080, in <module>
    main()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 1112, in main
    (rc, out, err) = service.modify_service_state()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 299, in modify_service_state
    return self.service_control()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 670, in service_control
    elif self.svc_cmd.endswith('rc-service'):
AttributeError: 'NoneType' object has no attribute 'endswith'
```



Discussion:
Can you please include steps to reproduce this problem as documented under "Reporting a Bug" in https://github.com/ansible/ansible/blob/devel/CONTRIBUTING.md ?  This will help us better understand how to test the problem.

I think all needed info is in pull request comment or is trivial, but not formatted correctly. So I'll try again. ;-)

FYI issue root cause is described in this comment: https://github.com/ansible/ansible/issues/3533#issuecomment-20998581

---

Ansible version: ansible 1.3 (devel d2bf244eb8) last updated 2013/09/13 15:51:09 (GMT +200)

Steps to reproduce: run following command against Debian Lenny:

```
ansible webserver.local -i webserver.local, -u root -m service -a 'name=apache2 state=restarted'
```

Excpected results:

```
webserver.local | success >> {
    "changed": true, 
    "name": "apache2", 
    "state": "started"
}
```

Actual results:

```
webserver.local | FAILED => failed to parse: Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 2080, in <module>
    main()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 1112, in main
    (rc, out, err) = service.modify_service_state()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 299, in modify_service_state
    return self.service_control()
  File "/root/.ansible/tmp/ansible-1379082596.06-63995244988034/service", line 670, in service_control
    elif self.svc_cmd.endswith('rc-service'):
AttributeError: 'NoneType' object has no attribute 'endswith'
```

Merged, thanks!


Resolving patch:
diff --git a/lib/ansible/modules/network/junos/junos_command.py b/lib/ansible/modules/network/junos/junos_command.py
--- a/lib/ansible/modules/network/junos/junos_command.py
+++ b/lib/ansible/modules/network/junos/junos_command.py
@@ -98,12 +98,13 @@
         output and apply the conditionals path to the result set.
     required: false
     default: 'xml'
-    choices: ['xml', 'text']
+    choices: ['xml', 'text', 'json']
 requirements:
   - junos-eznc
 notes:
   - This module requires the netconf system service be enabled on
-    the remote device being managed
+    the remote device being managed. 'json' format is supported
+    for JUNON version >= 14.2
 """
 
 EXAMPLES = """
@@ -219,7 +220,7 @@ def main():
         commands=dict(type='list'),
         rpcs=dict(type='list'),
 
-        display=dict(default='xml', choices=['text', 'xml'],
+        display=dict(default='xml', choices=['text', 'xml', 'json'],
                      aliases=['format', 'output']),
 
         wait_for=dict(type='list', aliases=['waitfor']),


Test patch: