# Reboot wait for port to come available

**URL:** <https://forum.ansible.com/t/reboot-wait-for-port-to-come-available/31519>\
**Category:** Ansible Project\
**Created:** [October 22, 2019, 10:42pm UTC](https://forum.ansible.com/t/reboot-wait-for-port-to-come-available/31519 "2019-10-22T22:42:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [October 22, 2019, 10:42pm UTC](https://forum.ansible.com/t/reboot-wait-for-port-to-come-available/31519/1 "2019-10-22T22:42:18Z")

</div>

Hi all,

So I know how to do this for the most part, but I’ve got two servers that when I have to reboot them, one needs to be done before the other and cannot before a specific port comes available. That port is only accessible from that second server, not the ansible server itself. Does that make sense?

Is there a way that I can create a playbook that will do what I’m describing?

ie

Reboot server1

Reboot server2 when tcp/3306 comes available on server1. **tcp/3306 is only open to server2.**

---

<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:** [October 22, 2019, 11:07pm UTC](https://forum.ansible.com/t/reboot-wait-for-port-to-come-available/31519/2 "2019-10-22T23:07:31Z")

</div>

Use the reboot module on server1, it will wait for the server to be available again.  
Then in the next task you can use the wait\_for module on server2 to check the port 3306.

Pseudo code for 2 play in one playbook.

- hosts: server1  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- reboot:

- hosts: server2  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- wait\_for:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host: server1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port: 3306  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: started

&nbsp;&nbsp;&nbsp;&nbsp;- reboot:

or in one play

- hosts: server1,server2  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- reboot:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: inventory\_hostname == "server1"

&nbsp;&nbsp;&nbsp;&nbsp;- wait\_for:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host: server1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port: 3306  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: started  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: inventory\_hostname == "server2"

&nbsp;&nbsp;&nbsp;&nbsp;- reboot:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: inventory\_hostname == "server2"

---

<div class="post-metadata">

**Author:** ![Chris\_Bidwell](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Chris\_Bidwell](https://forum.ansible.com/u/Chris_Bidwell)\
**Post date:** [October 23, 2019, 1:52pm UTC](https://forum.ansible.com/t/reboot-wait-for-port-to-come-available/31519/3 "2019-10-23T13:52:36Z")

</div>

Doesn’t this use the ansible server running the playbook to check if the port is open?
