Skip to content

Instantly share code, notes, and snippets.

@SethosII
Last active June 8, 2017 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethosII/4f822530d125fdf60ef70a3fa23f2676 to your computer and use it in GitHub Desktop.
Save SethosII/4f822530d125fdf60ef70a3fa23f2676 to your computer and use it in GitHub Desktop.
Ansible tasks to reboot hosts and wait for them to come back. Originally from https://support.ansible.com/hc/en-us/articles/201958037-Reboot-a-server-and-wait-for-it-to-come-back, but this article is no longer available. See also https://sethosii.github.io/2017/04/29/ansbile-reboot.html.
- name: "reboot hosts"
shell: "sleep 2 && shutdown -r now 'Reboot triggered by Ansible'" # sleep 2 is needed, else this task might fail
async: "1" # run asynchronously
poll: "0" # don't ask for the status of the command, just fire and forget
ignore_errors: yes # this command will get cut off by the reboot, so ignore errors
- name: "wait for hosts to come up again"
wait_for:
host: "{{ inventory_hostname }}"
port: "22" # wait for ssh as this is what is needed for ansible
state: "started"
delay: "120" # start checking after this amount of time
timeout: "360" # give up after this amount of time
delegate_to: "localhost" # check from the machine executing the playbook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment