aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2020-01-24 14:56:57 +0000
committerPeter Mikus <pmikus@cisco.com>2020-02-04 15:22:38 +0000
commit2cf0755933dac3e95c10928347996bad3cbe0a42 (patch)
tree89a79eb7b4a27e47b60b4ac1e6bb6eb56903b781 /resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml
parent35024b691ade4278f49d8a65d237c7112fa32bc2 (diff)
Ansible: Cleanup and speedup
Signed-off-by: Peter Mikus <pmikus@cisco.com> Change-Id: Ia2ce482798204ad426f93f334c97e28eb51139fd
Diffstat (limited to 'resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml')
-rw-r--r--resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml47
1 files changed, 26 insertions, 21 deletions
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
index 4a1180b77f..a593fc7616 100644
--- a/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml
+++ b/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/kill_process.yaml
@@ -1,27 +1,32 @@
---
# file: roles/cleanup/tasks/kill_process.yaml
-- 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 - {{ 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
+ - 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
+ - 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
+ - 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!"