Registering service output fails

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

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.

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

Thanks