# Ansible role with a reboot fails

**URL:** <https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304>\
**Category:** Ansible Project\
**Created:** [April 17, 2018, 6:47pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304 "2018-04-17T18:47:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [April 17, 2018, 6:47pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304/1 "2018-04-17T18:47:13Z")

</div>

I’ve trying to write an Ansible role that upgrades Github. The command to upgrade the server “ghe-upgrade github-2.13.1.pkg” for example, reboots the server, and when that happens, I get, the following connection because my ssh connection drops of course.

`

TASK [github : Upgrade [github1.company.com](http://github1.company.com) with version 2.13.1] \*\*\*\*\*\*\*\*\*\*  
fatal: [[github1.company.com](http://github1.company.com)]: UNREACHABLE! =\> {“changed”: false, “msg”: "Failed to connect to the host via ssh: ", “unreachable”: true}  
to retry, use: --limit @/build/workspace/team\_SCSCM/github/github-upgrade.retry

`

I tried the ideas from [ansible-reboot-and-wait.yml exmaple](https://gist.github.com/infernix/a968f23c4f4e1d6723e4), and others with similar approach, to no avail. So my tasks look like

`

# This command will reboot the node

- name: Upgrade Github host  
command: “ghe-upgrade {{ pkg\_dir }}/{{ pkg\_name }} --yes”

(It craps out after above task)

# Now we will run a local ‘ansible -m ping’ on this host until it returns.

# This works with the existing ansible hosts inventory and so any custom ansible\_ssh\_hosts definitions are being used

- local\_action: shell ansible -u {{ ansible\_ssh\_user }} -m ping [github1.company.com](http://github1.company.com)  
register: result  
until: result.rc == 0  
retries: 30  
delay: 10

`

Any pointers on how I can make this work? Thanks!

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [April 17, 2018, 8:28pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304/2 "2018-04-17T20:28:22Z")

</div>

Sorry, ignore my last post… I can see that is exactly what you did

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 17, 2018, 9:11pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304/3 "2018-04-17T21:11:16Z")

</div>

> I tried the ideas from ansible-reboot-and-wait.yml exmaple  
> \<[https://gist.github.com/infernix/a968f23c4f4e1d6723e4&gt;](https://gist.github.com/infernix/a968f23c4f4e1d6723e4&gt;), and others with

That's over 4 years old, in this profession that is a lifetime.

> similar approach, to no avail. So my tasks look like
> 
> # This command will reboot the node  
> - name: Upgrade Github host  
> &nbsp;&nbsp;command: "ghe-upgrade {{ pkg\_dir }}/{{ pkg\_name }} --yes"
> 
> (It craps out after above task)
> 
> # Now we will run a local 'ansible -m ping' on this host until it returns.  
> # This works with the existing ansible hosts inventory and so any custom  
> ansible\_ssh\_hosts definitions are being used  
> - local\_action: shell ansible -u {{ ansible\_ssh\_user }} -m ping  
> github1.company.com  
> &nbsp;&nbsp;register: result  
> &nbsp;&nbsp;until: result.rc == 0  
> &nbsp;&nbsp;retries: 30  
> &nbsp;&nbsp;delay: 10
> 
> Any pointers on how I can make this work? Thanks!

If it's possible to make ghe-upgrade not reboot the server that would be easiest I guess.  
The reason is you don't not how long the upgrade process will take and make it hard to find a value for the delay bellow.

The reboot is as simple as

- name: reboot server  
&nbsp;&nbsp;&nbsp;shell: sleep 2 && reboot  
&nbsp;&nbsp;&nbsp;async: 1  
&nbsp;&nbsp;&nbsp;poll: 0

- name: Wait for server  
&nbsp;&nbsp;&nbsp;wait\_for\_connection:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delay: 60

The delay must be at least as long it takes for the server to shutdown ssh, it not it will be able to connect again and the play continues.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 17, 2018, 11:16pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304/4 "2018-04-17T23:16:33Z")

</div>

Not quite exactly - there was no pause task in the OP’s version.

The linked webpage says that the pause is needed to prevent the existing control connection being used.

Regards, K.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [April 18, 2018, 1:08pm UTC](https://forum.ansible.com/t/ansible-role-with-a-reboot-fails/27304/5 "2018-04-18T13:08:40Z")

</div>

Thanks all. Yes there should’ve been a pause between the two tasks. And yes there is an option to not reboot during the ghe-upgrade procedure, but I still would need to reboot twice after the command, once for Github to finish its upgrade, and another for the upgrade to take effect. So I still would to use the tricks mentioned here.
