I\'m trying to reboot server running CentOS 7 on VirtualBox. I use this task:
- name: Restart server
command: /sbin/reboot
async: 0
poll:
Another solution:
- name: reboot host
command: /usr/bin/systemd-run --on-active=10 /usr/bin/systemctl reboot
async: 0
poll: 0
- name: wait for host sshd
local_action: wait_for host="{{ inventory_hostname }}" search_regex=OpenSSH port=22 timeout=300 delay=30
systemd-run creates "on the fly" new service which will start systemctl reboot after 10 sec of delay (--on-active=10).
delay=30 in wait_for to add extra 20 sec to be sure that host actually started rebooting.