# requires --extra-vars="target=hostspec"

- name: reboot hosts
  hosts: $target
  user: root
  serial: 1

  tasks:
  - name: see if it needs to be rebooted
    action: command /usr/local/bin/needs-reboot.py
    register: needsreboot

  - name: tell nagios to shush
    action: nagios action=silence host=${inventory_hostname_short}
    delegate_to: noc01.phx2.fedoraproject.org
    only_if: "'${needsreboot.stdout}'.find('yes') != -1"

  - name: reboot the host
    action: command /sbin/reboot
    only_if: "'${needsreboot.stdout}'.find('yes') != -1"

  - name: wait for host to come back - up to 6 minutes
    local_action: wait_for host=${inventory_hostname} port=22 delay=30 timeout=420
    only_if: "'${needsreboot.stdout}'.find('yes') != -1"

  - name: tell nagios to unshush
    action: nagios action=unsilence host=${inventory_hostname_short}
    delegate_to: noc01.phx2.fedoraproject.org
    only_if: "'${needsreboot.stdout}'.find('yes') != -1"



