firasKoubaa
firasKoubaa

Reputation: 6867

Shell how to kill a process and return 0

Using Ansible i have this simple task :

- name: kill selected APIS processes on API SERVER
  shell: kill $(pgrep -f {{item}})

This process would be well killed but the task throws an error :

failed: "msg": "non-zero return code",

As indicated , maybe i should force my shell script to return 0 value (success)

kill $(pgrep -f {{item}})

how to do it ?

Upvotes: 1

Views: 2103

Answers (1)

William Pursell
William Pursell

Reputation: 212268

The typical idiom to always return 0 is kill $(pgrep -f {{item}}) || true

But in ansible, it would seem sensible to use ignore_errors.

Upvotes: 4

Related Questions