We’ve been working on a playbook that does a dist upgrade and then performs a reboot. This has been problematic and results in a failure return status that sometimes means it worked and sometimes not. What is the trick to reboots – being able to smoothly reconnect after a reboot signal?
Just a guess but you might want to have a few seconds of delay set in your wait_for so that there is time for network services and sshd to come back up before ansible goes looking for it.
Your server may still be in the process of shutting down when your “wait_for” is executed. So the wait_for could make a connection and think the server is back up when it is actually on its way down…
Try setting the delay parameter in the wait_for (e.g to 15) to ensure that the server is down/rebooting before waif_for starts checking.