Reboot and reconnect between Ansible tasks
You can reboot and reconnect to your hosts between Ansible tasks.
# Other task above here.
# Now reboot and reconnect
- block:
# The at module allows ansible to issue the command and disconnect
# cleanly before the reboot disconnects the network connection.
- name: Reboot in one minute
at: command=reboot count=1 units=minutes
# You may need to adjust this dependong on how fast your host halts.
- name: Wait for reboot to start and hopefully finish
pause: minutes=2
- name: Try to re-connect to rebooted host before continuing
command: /bin/true
register: online
retries: 20
delay: 30
until: online|success
# Continue your tasks...
Update 5 Jan 2017
Here's another option using the wait_for module.
- name: reboot
at: command=reboot count=1 units=minutes
- name: wait for sshd on vms to resume
wait_for:
host: maple.example.com
port: 22
delay: 90
# Continue your tasks...