Skip to content

Instantly share code, notes, and snippets.

@rsevilla87
Created June 26, 2018 08:10
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 rsevilla87/6a206f296e171b429cb8d021ff6c810d to your computer and use it in GitHub Desktop.
Save rsevilla87/6a206f296e171b429cb8d021ff6c810d to your computer and use it in GitHub Desktop.
Reboot system with Ansible and wait of it to come back
- hosts: all
become: yes
gather_facts: no
remote_user: cloud-user
tasks:
- name: "Reboot system"
shell: sleep 5 && /usr/sbin/reboot
async: 1
poll: 0
- name: "Wait for server to finish reboot"
wait_for_connection:
timeout: 120
delay: 10
@rsevilla87
Copy link
Author

With the reboot module available since Ansible 2.7 things become easier :-)

Ad an ad-hoc command

$ ansible -m reboot -i <inventory> all

or in a playbook

- hosts: all
  become: yes
  tasks:
    - name: Rebooting nodes
      reboot:
        reboot_timeout: 3600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment