# \[feature #5785\] Reboot module merits

**URL:** <https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631>\
**Category:** Ansible Developer\
**Created:** [February 21, 2014, 10:44pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631 "2014-02-21T22:44:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoff\_Oakham](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Geoff\_Oakham](https://forum.ansible.com/u/Geoff_Oakham)\
**Post date:** [February 21, 2014, 10:44pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/1 "2014-02-21T22:44:52Z")

</div>

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:

1. ‘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.

2. ‘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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 21, 2014, 10:54pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/2 "2014-02-21T22:54:08Z")

</div>

So I guess the question from me is, how would you implement it?

---

<div class="post-metadata">

**Author:** ![Geoff\_Oakham](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Geoff\_Oakham](https://forum.ansible.com/u/Geoff_Oakham)\
**Post date:** [February 21, 2014, 11:27pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/3 "2014-02-21T23:27:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [February 21, 2014, 11:30pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/4 "2014-02-21T23:30:26Z")

</div>

- name: reboot  
&nbsp;&nbsp;&nbsp;command: shutdown -r now

- name: wait for ping  
&nbsp;&nbsp;&nbsp;ping:  
&nbsp;&nbsp;&nbsp;register: waiting  
&nbsp;&nbsp;&nbsp;until: waiting|success  
&nbsp;&nbsp;&nbsp;retries: 10  
&nbsp;&nbsp;&nbsp;delay: 20

Use the internal ping module, attempt it 10 times, waiting 20 seconds between each attempt.

-jlk

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 22, 2014, 12:16am UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/5 "2014-02-22T00:16:01Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [February 22, 2014, 12:26am UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/6 "2014-02-22T00:26:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 22, 2014, 1:27am UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/7 "2014-02-22T01:27:51Z")

</div>

Yep, good point!

---

<div class="post-metadata">

**Author:** ![Geoff\_Oakham](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@Geoff\_Oakham](https://forum.ansible.com/u/Geoff_Oakham)\
**Post date:** [February 24, 2014, 3:33pm UTC](https://forum.ansible.com/t/feature-5785-reboot-module-merits/14631/8 "2014-02-24T15:33:16Z")

</div>

(ps. I keep mis-reading “Ansible Development” as “Arrested Development”)
