1

I have a task in my playbook to kill all the processes of a given name:

- name: stop twd if running
      #shell: ps auxww | grep 'twd' | awk '{print $2}' | xargs kill -9
      shell: pkill pwd
      become: yes
      ignore_errors: yes

It returns non-zero code and the debug mode does not give me why it has failed, it only says:

"invocation": {
        "module_args": {
            "_raw_params": "pkill twd",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    }, 
    "msg": "non-zero return code", ...

Why it fails while the user that runs the command is true and when I run the same command on the remote machine, it works. From the documents the 'shell' task work exactly the same as running the command through the shell on the remote machine, why does it fail? It can execute other commands, but it fails to execute the commands I send to kill the process.
this is the results of running the command on the remote machine which returns exit code of 0:

root@mos:~# pkill twd
root@mos:~# echo $?
0

A similar question, here, suggests that we should use 'shell' instead of 'command' when we use pipe or when we need to access an env variable, it also suggests to add ignore_error if this is not a real failure. I used shell and the commented task above that uses pipe and it didn't work and even after using the 'pkill' command that does not include any pipe, it fails.

0

You must log in to answer this question.

Browse other questions tagged .