# Registering service output fails

**URL:** <https://forum.ansible.com/t/registering-service-output-fails/14811>\
**Category:** Ansible Project\
**Created:** [March 20, 2014, 12:48pm UTC](https://forum.ansible.com/t/registering-service-output-fails/14811 "2014-03-20T12:48:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Van\_der\_Kuss](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@Vincent\_Van\_der\_Kuss](https://forum.ansible.com/u/Vincent_Van_der_Kuss)\
**Post date:** [March 20, 2014, 12:48pm UTC](https://forum.ansible.com/t/registering-service-output-fails/14811/1 "2014-03-20T12:48:09Z")

</div>

Hi,

I've a playbook where I register the state of a service. I have a  
task in the same playbook that is executed based on the output of the  
registered state.  
Everything works but when the service is stopped the task that  
registers the state returns failed.

Functionally it works. when the service is stopped the task that  
should stop the service is skipped. When the service is running, the  
service is stopped. I only have a problem that the output of the task  
where i register the output returns FAILED when the service is  
stopped.

I'm not sure if i'm doing something wrong.

To make it a bit more clear :

Tasks in the playbook

---

<div class="post-metadata">

**Author:** ![Christian\_Thiemann](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@Christian\_Thiemann](https://forum.ansible.com/u/Christian_Thiemann)\
**Post date:** [March 20, 2014, 1:40pm UTC](https://forum.ansible.com/t/registering-service-output-fails/14811/2 "2014-03-20T13:40:40Z")

</div>

The init script’s status command exits with a non-zero return code if the service is not running (as per LSB specification, I believe), which Ansible interprets as an error (and ignores it as instructed).

Since the non-zero return code is not actually an error, instead of adding “ignore\_errors: yes” to the task, you could define what constitutes failure by adding “failed\_when: false” (task is never interpreted as failed) or some other other failed\_when condition that checks whether lgstatus.rc is not one of the expected LSB-specified values.

---

<div class="post-metadata">

**Author:** ![Vincent\_Van\_der\_Kuss](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@Vincent\_Van\_der\_Kuss](https://forum.ansible.com/u/Vincent_Van_der_Kuss)\
**Post date:** [March 20, 2014, 1:43pm UTC](https://forum.ansible.com/t/registering-service-output-fails/14811/3 "2014-03-20T13:43:27Z")

</div>

Good point. I didn't really thought of that.  
Will check that out.

Thanks
