I\'m trying to reboot server running CentOS 7 on VirtualBox. I use this task:
- name: Restart server
command: /sbin/reboot
async: 0
poll:
Following solution works for me perfect:
- name: Restart machine
shell: "sleep 5 && sudo shutdown -r now"
async: 1
poll: 0
- name: wait for ssh again available.
wait_for_connection:
connect_timeout: 20
sleep: 5
delay: 5
timeout: 300
Sleep is required because ansible requires few second's to wrap up connection. Excelent post about this problem was written here: https://www.jeffgeerling.com/blog/2018/reboot-and-wait-reboot-complete-ansible-playbook