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.
On Thursday, March 20, 2014 1:48:09 PM UTC+1, Vincent Van der Kussen wrote:
>
> 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
> --------------------------------
>
> - name: get lgserver status
> action: command /opt/lettergen/lgserver status
> register: lgstatus
> ignore_errors: True
>
> - name: stop lgserver
> action: command /opt/lettergen/lgserver stop
> when: lgstatus.stdout.find('running') != -1
>
>
>
> Output when service is stopped
> ----------------------------------------------
> TASK: [lg-update | get lgserver status]
> ***************************************
> failed: [192.168.192.11] => {"changed": true, "cmd":
> ["/opt/lettergen/lgserver", "status"], "delta": "0:00:00.158255",
> "end": "2014-03-20 13:39:05.970555", "item": "", "rc": 3, "start":
> "2014-03-20 13:39:05.812300"}
> stdout: The daemon is stopped.
> ...ignoring
>
>
> TASK: [lg-update | stop lgserver]
> *********************************************
> skipping: [192.168.192.11]
>
>
> Output when the service is started
> --------------------------------------------------
> TASK: [lg-update | stop lgserver]
> *********************************************
> changed: [192.168.192.11]
>
> Debug output of the registered value
> ----------------------------------------------------
> TASK: [lg-update | debug]
> *****************************************************
> ok: [192.168.192.11] => {
> "item": "",
> "lgstatus": {
> "changed": true,
> "cmd": [
> "/opt/lettergen/lgserver",
> "status"
> ],
> "delta": "0:00:00.158255",
> "end": "2014-03-20 13:39:05.970555",
> "invocation": {
> "module_args": "/opt/lettergen/lgserver status",
> "module_name": "command"
> },
> "item": "",
> "rc": 3,
> "start": "2014-03-20 13:39:05.812300",
> "stderr": "",
> "stdout": "The daemon is stopped.",
> "stdout_lines": [
> "The daemon is stopped."
> ]
> }
> }
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6ab374f7-7e13-4b43-9439-0875a63524b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.