Registering service output fails

42 views
Skip to first unread message

Vincent Van der Kussen

unread,
Mar 20, 2014, 8:48:09 AM3/20/14
to ansible...@googlegroups.com
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."
]
}
}

Christian Thiemann

unread,
Mar 20, 2014, 9:40:40 AM3/20/14
to ansible...@googlegroups.com
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.

Vincent Van der Kussen

unread,
Mar 20, 2014, 9:43:27 AM3/20/14
to ansible...@googlegroups.com
Good point. I didn't really thought of that.
Will check that out.

Thanks
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> 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.
Reply all
Reply to author
Forward
0 new messages