Created
May 10, 2014 16:55
-
-
Save infernix/a968f23c4f4e1d6723e4 to your computer and use it in GitHub Desktop.
Make Ansible reboot remote hosts and wait for them to return
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Reboot a host and wait for it to return | |
hosts: somehost | |
remote_user: root | |
tasks: | |
# Send the reboot command | |
- shell: shutdown -r now | |
# This pause is mandatory, otherwise the existing control connection gets reused! | |
- pause: seconds=30 | |
# Now we will run a local 'ansible -m ping' on this host until it returns. | |
# This works with the existing ansible hosts inventory and so any custom ansible_ssh_hosts definitions are being used | |
- local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ inventory_hostname }} | |
register: result | |
until: result.rc == 0 | |
retries: 30 | |
delay: 10 | |
# And finally, execute 'uptime' when the host is back. | |
- shell: uptime |
Thanks, yes I did see that. Based on that, I tried:
- hosts: all
- name: rebooting servers
reboot:
And I get this:
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator
The offending line appears to be:
- name: rebooting servers
reboot:
^ here
I apologize in advance if my block code above doesn't work
tasks:
- name: Reboot the server
reboot:
- pause:
prompt: "Need delay for restart"
seconds: 30
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is outdated; see comments for better options, most notablly https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html