Killing processes but not failing if they aren't there

I’m trying to kill a bunch of processes using an ansible task, but I don’t want the task to fail if there are no processes of interest.

I created a task that looks like this:

  • name: kill websocket server
    action: shell pgrep -f websockify | xargs kill || true

The problem is that this returns with a -15 return value, despite the || true at the end. Here’s what it looks like if I use the ansible command:

$ ansible vnc -m shell -a “pgrep -f websockify | xargs kill || true” -s
192.168.108.102 | FAILED | rc=-15 >>

Anybody know why I’d get a non-zero return code? If I just run the command as root, when it fails, I do get the 0 return value:

root@precise64:~# pgrep -f websockify | xargs kill || true
Usage:
kill pid … Send SIGTERM to every process listed.
kill signal pid … Send a signal to every process listed.
kill -s signal pid … Send a signal to every process listed.
kill -l List all signal names.
kill -L List all signal names in a nice table.
kill -l signal Convert between signal numbers and names.
root@precise64:~# echo $?
0

Here’s ansible version deatils

$ ansible --version
ansible 0.8 (devel c8854a23ea) last updated 2012/10/07 21:16:36 (GMT -400)

I'm trying to kill a bunch of processes using an ansible task, but I don't
want the task to fail if there are no processes of interest.

I created a task that looks like this:

   - name: kill websocket server
     action: shell pgrep -f websockify | xargs kill || true

I would go for:

   - name: kill websocket server
     action: shell pkill -f websockify
     ignore_errors: True

Anybody know why I'd get a non-zero return code? If I just run the command
as root, when it fails, I do get the 0 return value:

Might be a bug worth fixing, although I cannot reproduce this:

I would go for:

  - name: kill websocket server
    action: shell pkill -f websockify
    ignore_errors: True

+1

Anybody know why I'd get a non-zero return code? If I just run the
command
as root, when it fails, I do get the 0 return value:

No idea, doesn't seem to be an ansible thing and may be related to
your invocation in that particular instance?

In any event, should you wish to debug further, I'm interested in the results.

I’ll try to do some digging to figure out what’s going on here.

Take care,

Lorin

Give xargs a -r, wont execute with error on empty args