What's the correct way to reboot a server?

Hi everyone,

I’m new to Ansible and I’ve been exploring it with Vagrant to perform some automated deployment tests for a project. I’m enjoying it so far! As part of setting up the deployment environment, I need to adjust some kernel parameters which take effect at boot time. It’s easy to do: edit a file and reboot. I’m not sure how to do this using Ansible so that Ansible waits for the reboot to complete.

My first thought was use a pre_task to set the kernel parameters and notify a ‘reboot’ handler like this http://pastebin.com/A5BwUkY9 . But then other tasks would attempt to run in the middle of the reboot. I tried to resolve this using the “wait_for: port=22”, but no dice… perhaps because the ssh daemon doesn’t get killed before Ansible checks.

Am I on the right track? What am I missing?

Thanks,

Geoff

wait_for has a delay parameter so you can wait a given number of seconds before checking for port uptime.

This is generally what I’d suggest.

You can find an example here:

https://github.com/analytically/hadoop-ansible/blob/master/roles/2_aggregated_links/tasks/main.yml

Cheers,

Mathias