Can't make Ansible to wait for a server to reboot and continue playbook to work
This is a commonly known problem. See Reboot a server and wait for it to come back. Since Ansible 1.9.4 SSH loses connection before proceeding to the next task.
You need to add a delay (sleep
) before the shutdown
command:
- name: restart server
shell: sleep 2 && shutdown -r now
async: 1
poll: 0
become: yes
become_method: sudo
ignore_errors: true
- name: waiting for server to come back after reboot
wait_for_connection:
....
On Ansible 2.7, the reboot
module was introduced, which solves this problem.
You can use:
- name: restart server
reboot: