ansible-labs/110.Conditional/solution/solution.yml

22 lines
539 B
YAML

- hosts: lab
gather_facts: true
tasks:
- name: Reboot the host if it is up for more than 600s
shell: nohup sh -c '(sleep 5 ; reboot)'
become: true
poll: 0
async: 1
ignore_errors: true
when: ansible_uptime_seconds > 600
notify:
- Wait for Reboot
- Rebooted msg
handlers:
- name: Wait for Reboot
wait_for_connection:
delay: 10
- name: Rebooted msg
debug:
msg: "Host {{ ansible_ssh_host }} has been rebooted"
# vim: set ft=yaml sw=2 et: