Hi guys,
I suggested a “reboot module” as a feature request (#5785) and it was suggested I bring it to the mailing list for discussion. Here I am!
So… what are the cons of having a reboot module?
In the feature discussion, it was pointed out there’s a workaround that works for most people: chain either a “pause” handler, or a “wait_for ” handler. I don’t know what “best practices” are in ansible, but both of these seem “hackish” to me. My thoughts in detail:
-
‘pause’ works, but is fragile. It will break if you’re running on a slow machine (eg. laptop). Alternatively, using a longer timeout will waste time. Further, if there’s a problem during reboot, the original cause could be masked.
-
‘wait_for ’… how do you know what the hostname and ssh port number is? I’m playing with Vagrant, and I think those are mapped to “localhost” and some random port.
But lastly, it seems common enough problem that Vagrant users could benefit from it.
I’m probably way off, so I’m looking forward to learning something new about Ansible in this discussion!
Thanks,
Geoff
So I guess the question from me is, how would you implement it?
I would implement it the same way wait_for workaround works: issue a “shutdown -r now” on the client, and then use “wait_for” to watch the ssh port disappear and the re-appear. Ansible knows the host and ssh port, because it’s now it communicates with the client. (Better yet, if there is an internal “ping” function to check if a host is up, that would be a better than wait_for since it since it’s agnostic of the method of communication with the client. And really, we don’t care about ssh, )
Anyways, I couldn’t figure out how to code it. Because it’d need two separate parts (the “shutdown” part, and the “wait for ssh to come back up” part) it doesn’t fit the bill of a “normal” module. I don’t know a clean way of doing this.
- name: reboot
command: shutdown -r now
- name: wait for ping
ping:
register: waiting
until: waiting|success
retries: 10
delay: 20
Use the internal ping module, attempt it 10 times, waiting 20 seconds between each attempt.
-jlk
Nice way to do this without having to pass the port along, though I’m thinking you can just use {{ ansible_ssh_port }} on the wait for too. The current remote hostname is given by {{ ansible_ssh_host }}
(These are more or less the same things, wait_for did polling prior to do/until existing)
Yup, We use the ssh method in our stuff, but that presumes an ssh connection method in use. ping will use the configured connection method, which may be something entirely different (although rebooting while using fireball would be... awkward).
-jlk
(ps. I keep mis-reading “Ansible Development” as “Arrested Development”)