# Debugging service module

**URL:** <https://forum.ansible.com/t/debugging-service-module/15183>\
**Category:** Ansible Project\
**Created:** [May 7, 2014, 12:52pm UTC](https://forum.ansible.com/t/debugging-service-module/15183 "2014-05-07T12:52:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 7, 2014, 12:52pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/1 "2014-05-07T12:52:52Z")

</div>

I’m running ansible 1.5.5 against a CentOS 6 server, and trying to use the “service” module to manage an upstart job. However, I keep getting this error from ansible:

$ ansible [bastion3.hadoop.ripe.net](http://bastion3.hadoop.ripe.net) -i svn/gii/ansible\_hosts -sK -m service -a ‘name=hdfs-sync state=stopped’  
sudo password:  
[bastion3.hadoop.ripe.net](http://bastion3.hadoop.ripe.net) | FAILED =\> failed to parse:  
SUDO-SUCCESS-mwcdqmpymyognbdmbrqkqbkccfdmzwqs  
Traceback (most recent call last):  
File “/tmp/ansible-tmp-1399466909.49-7501828270786/service”, line 2305, in   
main()  
File “/tmp/ansible-tmp-1399466909.49-7501828270786/service”, line 1170, in main  
service.get\_service\_status()  
File “/tmp/ansible-tmp-1399466909.49-7501828270786/service”, line 480, in get\_service\_status  
rc, status\_stdout, status\_stderr = self.service\_control()  
File “/tmp/ansible-tmp-1399466909.49-7501828270786/service”, line 722, in service\_control  
rc\_state, stdout, stderr = self.execute\_command(“%s %s %s” % (self.action, self.name, arguments), daemonize=True)  
File “/tmp/ansible-tmp-1399466909.49-7501828270786/service”, line 250, in execute\_command  
return json.loads(data)  
File “/usr/lib64/python2.6/json/ **init**.py”, line 307, in loads  
return \_default\_decoder.decode(s)  
File “/usr/lib64/python2.6/json/decoder.py”, line 319, in decode  
obj, end = self.raw\_decode(s, idx=\_w(s, 0).end())  
File “/usr/lib64/python2.6/json/decoder.py”, line 338, in raw\_decode  
raise ValueError(“No JSON object could be decoded”)  
ValueError: No JSON object could be decoded

If I log into the server, and run “stop hdfs-sync” or “status hdfs-sync” or “start hdfs-sync” it all works. My ansible setup also works against other CentOS 6 boxes just fine, and can start, stop and restart other upstart jobs just fine. So this is a weird case. How can I debug this more, and find out why ansible is failing with this specific upstart job on this server.

Anand

---

<div class="post-metadata">

**Author:** ![Strahinja\_Kustudic2](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Strahinja\_Kustudic2](https://forum.ansible.com/u/Strahinja_Kustudic2)\
**Post date:** [May 7, 2014, 10:57pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/2 "2014-05-07T22:57:36Z")

</div>

You could set an environment variable:

`  
ANSIBLE\_KEEP\_REMOTE\_FILES=1

`

and run ansible again. Once it fails, see what files were executed, log into the remote host and run the failed python script with:

`python -m trace --trace script.py`

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 8, 2014, 2:15pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/3 "2014-05-08T14:15:04Z")

</div>

Thanks for this tip. I did exactly as you describe, and ran the script on the host. To my surprise, it did what it was supposed to! The last few lines from the trace output show:

— modulename: encoder, funcname: \_iterencode\_dict  
encoder.py(281): if markers is not None:  
encoder.py(282): del markers[markerid]  
encoder.py(368): return ‘’.join(chunks)  
{“state”: “stopped”, “changed”: true, “name”: “hdfs-sync”}  
service(2146): sys.exit(0)

The service stopped running, so the script did its work. I don’t understand why I get an error from ansible on my laptop then. Any ideas developers?

Anand

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [May 8, 2014, 8:50pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/4 "2014-05-08T20:50:26Z")

</div>

Actually, this looks like a bug that occurred with script and raw in some earlier versions of Ansible where the sudo success string was being leaked back. It was fixed, I’m now wondering if it was reverted in this case…

Can you upgrade to 1.6.1 and try it again?

Adam

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 8, 2014, 8:56pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/5 "2014-05-08T20:56:35Z")

</div>

Hi Adam, it still fails:

$ ansible --version  
ansible 1.6.1  
$ ansible [bastion3.hadoop.ripe.net](http://bastion3.hadoop.ripe.net) -sK -m service -a ‘name=hdfs-sync state=restarted’  
sudo password:  
[bastion3.hadoop.ripe.net](http://bastion3.hadoop.ripe.net) | FAILED =\> failed to parse:  
SUDO-SUCCESS-dawyrikofupcjoyftolafyddywphopwj  
Traceback (most recent call last):  
File “/tmp/ansible-tmp-1399582444.03-10583586416099/service”, line 2411, in   
main()  
File “/tmp/ansible-tmp-1399582444.03-10583586416099/service”, line 1198, in main  
service.get\_service\_status()  
File “/tmp/ansible-tmp-1399582444.03-10583586416099/service”, line 509, in get\_service\_status  
rc, status\_stdout, status\_stderr = self.service\_control()  
File “/tmp/ansible-tmp-1399582444.03-10583586416099/service”, line 750, in service\_control  
rc\_state, stdout, stderr = self.execute\_command(“%s %s %s” % (self.action, self.name, arguments), daemonize=True)  
File “/tmp/ansible-tmp-1399582444.03-10583586416099/service”, line 250, in execute\_command  
return json.loads(data)  
File “/usr/lib64/python2.6/json/ **init**.py”, line 307, in loads  
return \_default\_decoder.decode(s)  
File “/usr/lib64/python2.6/json/decoder.py”, line 319, in decode  
obj, end = self.raw\_decode(s, idx=\_w(s, 0).end())  
File “/usr/lib64/python2.6/json/decoder.py”, line 338, in raw\_decode  
raise ValueError(“No JSON object could be decoded”)  
ValueError: No JSON object could be decoded

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [May 8, 2014, 9:09pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/6 "2014-05-08T21:09:56Z")

</div>

There is an open bug report [https://github.com/ansible/ansible/issues/7319](https://github.com/ansible/ansible/issues/7319) which sounds very similar…

Do you need to provide a password to use sudo on the remote host? Do you need to use sudo? I’m curious because that first line SUDO-SUCCESS … should be being eaten by part of ansible…

Adam

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 8, 2014, 9:28pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/7 "2014-05-08T21:28:36Z")

</div>

Hi Adam,

> There is an open bug report [https://github.com/ansible/ansible/issues/7319](https://github.com/ansible/ansible/issues/7319) which sounds very similar…

Yes, this bug report sounds a lot like what I’m experiencing.

> Do you need to provide a password to use sudo on the remote host? Do you need to use sudo? I’m curious because that first line SUDO-SUCCESS … should be being eaten by part of ansible…

On the remote host, I need to use sudo to run commands as root, and I need to provide a password.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 9, 2014, 3:57pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/8 "2014-05-09T15:57:02Z")

</div>

This isn't an upstart script is it?

I saw something very very similar if I tried to set enabled=no on an  
upstart-managed  
service on CentOS a few weeks back. Removing that clause made it work.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 9, 2014, 11:44pm UTC](https://forum.ansible.com/t/debugging-service-module/15183/9 "2014-05-09T23:44:36Z")

</div>

This is a traceback in the service module, certaintly.

Please be sure there’s a ticket open and if you don’t have the same issue, file a new ticket, and we’ll look into this promptly.

We take the position that a traceback is always a bug in nearly all cases, modules should return reasonable errors if they ever have to fail, etc.

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 10, 2014, 9:21am UTC](https://forum.ansible.com/t/debugging-service-module/15183/10 "2014-05-10T09:21:26Z")

</div>

Hi Dick,

> This isn’t an upstart script is it?
> 
> I saw something very very similar if I tried to set enabled=no on an  
> upstart-managed  
> service on CentOS a few weeks back. Removing that clause made it work.

Yes, as my original message said, this is an upstart script.

Anand

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [May 10, 2014, 9:22am UTC](https://forum.ansible.com/t/debugging-service-module/15183/11 "2014-05-10T09:22:51Z")

</div>

Hi Michael,

> This is a traceback in the service module, certaintly.
> 
> Please be sure there’s a ticket open and if you don’t have the same issue, file a new ticket, and we’ll look into this promptly.

I believe my issue is very similar, and possibly the same, as issue #7319.
