title: How to kill a running process using ansible?
body: <p>I have an ansible playbook to kill running processes and works great most of the time!, however, from time to time we find processes that just can't be killed so, "wait_for" gets to the timeout, throws an error and it stops the process. </p>
  
  <p>The current workaround is to manually go into the box, use "kill -9" and run the ansible playbook again so I was wondering if there is any way to handle this scenario from ansible itself?, I mean, I don't want to use kill -9 from the beginning but I maybe a way to handle the timeout?, even to use kill -9 only if process hasn't been killed in 300 seconds? but what would be the best way to do it?</p>
  
  <p>These are the tasks I currently have: </p>
  
  <pre><code>- name: Get running processes
    shell: "ps -ef | grep -v grep | grep -w {{ PROCESS }} | awk '{print $2}'"
    register: running_processes
  
  - name: Kill running processes
    shell: "kill {{ item }}"
    with_items: "{{ running_processes.stdout_lines }}"
  
  - name: Waiting until all running processes are killed
    wait_for:
      path: "/proc/{{ item }}/status"
      state: absent
    with_items: "{{ running_processes.stdout_lines }}"
  </code></pre>
  
  <p>Thanks!</p>