# This ansible script will restart a bot if it is not currently running a swarming task.
---
- hosts: all
  remote_user: chrome-bot
  become_user: root
  become: yes
  become_method: sudo
  tasks:

     - name: Check for a running swarming task.
       shell: ps aux | grep task_runner | wc -l
       register: process_count

     # If there is a running task, ansible reports 3 (or more) results from ps
     # I believe this to because the grep command itself has "task_runner" in it
     # and the ansible shell part that triggers the command has "task_runner" in it
     # so 2 is the baseline, 3 or more means swarming added 1 (or more) lines
     - name: Reboot if there is not a running task
       command: reboot
       ignore_errors: yes
       when: process_count.stdout|int <= 2

Add ansible script to restart many bots if they aren't running a task
Add ansible script to restart many bots if they aren't running a task

Run this like: 
ansible-playbook -i rpi-hosts restart_if_not_busy.yml  -vv

Bug: skia:7242
Change-Id: I84a3622eaf9066fd57df63fb5de63b024a90d4d9
Reviewed-on: https://skia-review.googlesource.com/65021
Reviewed-by: Eric Boren <0e499112533c8544f0505ea0d08394fb5ad7d8fa@google.com>
