Skip to content

Instantly share code, notes, and snippets.

@bioshazard
Created September 25, 2020 23:50
Show Gist options
  • Save bioshazard/50a881b855b8ea8f80226b13219ee05e to your computer and use it in GitHub Desktop.
Save bioshazard/50a881b855b8ea8f80226b13219ee05e to your computer and use it in GitHub Desktop.
---
# EXAMPLE: ansible-playbook -i inventory/local-vagrant/hosts --diff reboot.yml -e reboot_hosts=utility,dev,sandbox
- hosts: "{{reboot_hosts}}"
become: yes
# Reboot one at a time to enable play failure if any don't come back
serial: 1
tasks:
- debug:
msg: "Rebooting {{inventory_hostname_short}}"
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html
- name: "Reboot {{inventory_hostname_short}}"
reboot:
reboot_timeout: 120
register: reboot_result
ignore_errors: true
- debug:
msg: "{{reboot_result}}"
# NOTE: We could put a notification task or something here if we wanted
- debug:
msg: "Failure caught, exiting play..."
failed_when: true
when: reboot_result.failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment