Skip to content

Instantly share code, notes, and snippets.

@silviot
Last active May 9, 2018 07:46
Show Gist options
  • Save silviot/815c72caa9da8238c7c4d542d4fa72a6 to your computer and use it in GitHub Desktop.
Save silviot/815c72caa9da8238c7c4d542d4fa72a6 to your computer and use it in GitHub Desktop.
Reboot server and wait for restart with ansible
# After way too many attempts, this one seems to really work all the time
- name: Reboot server
shell: sleep 2 && reboot
async: 1
poll: 0
failed_when: false
become: true
- name: Wait for server to initiate shutdown
wait_for:
host: "{{ ansible_ssh_host }}"
state: stopped
port: 22
delegate_to: localhost
- name: Wait for server to come back online
wait_for:
host: "{{ ansible_ssh_host }}"
state: started
port: 22
delegate_to: localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment