A quick one today. The following ansible tasks check if a server needs to be rebooted, reboots it, and then waits for it to come back online. Easy to fire off during a maintenance after updating packages.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
- name: reboot server if /var/run/reboot-required exists
command: shutdown -r now
args:
removes: /var/run/reboot-required
- name: wait until rebooted
local_action: wait_for host={{ inventory_hostname }} port=22 state=started delay=30
- name: give sshd a few seconds to start up fully
raw: echo ssh subsystem online
register: result
until: result.stdout.find("ssh subsystem online") != -1
retries: 50
delay: 10
|