X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Ftestbed-setup%2Fansible%2Froles%2Fcleanup%2Ftasks%2Fkill_process.yaml;fp=resources%2Ftools%2Ftestbed-setup%2Fansible%2Froles%2Fcleanup%2Ftasks%2Fkill_process.yaml;h=a593fc761691d458a83cf64855698cfd48a90167;hp=0000000000000000000000000000000000000000;hb=048a9ca3484a06e54f48dc80e7ab24dbfebe406f;hpb=d7aec8ee052468f55e2e9bd27de1dedd918c8a37 diff --git a/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml b/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml new file mode 100644 index 0000000000..a593fc7616 --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml @@ -0,0 +1,32 @@ +--- +# file: roles/cleanup/tasks/kill_process.yaml + +- name: Kill process - {{ process }} + block: + - name: Kill process - Get pid of {{ process }} + shell: "ps -ef | grep -v grep | grep -w {{ process }} | awk '{print $2}'" + when: > + process is defined and process != "" + register: running_processes + tags: kill-process + + - name: Kill process - Safe kill {{ process }} + shell: "kill {{ item }}" + with_items: "{{ running_processes.stdout_lines }}" + tags: kill-process + + - wait_for: + path: "/proc/{{ item }}/status" + state: absent + with_items: "{{ running_processes.stdout_lines }}" + ignore_errors: yes + register: killed_processes + tags: kill-process + + - name: Kill process - Force kill {{ process }} + shell: "kill -9 {{ item }}" + with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}" + tags: kill-process + rescue: + - fail: + msg: "Kill process {{ process }} failed!"