Reboot wait for port to come available

8 views
Skip to first unread message

Chris Bidwell - NOAA Federal

unread,
Oct 22, 2019, 6:42:44 PM10/22/19
to ansible...@googlegroups.com
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.

Kai Stian Olstad

unread,
Oct 22, 2019, 7:07:44 PM10/22/19
to ansible...@googlegroups.com
> Reboot server2 when tcp/3306 comes available on server1. *tcp/3306 is only
> open to server2.*

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
tasks:
- reboot:

- hosts: server2
tasks:
- wait_for:
host: server1
port: 3306
state: started

- reboot:

or in one play

- hosts: server1,server2
tasks:
- reboot:
when: inventory_hostname == "server1"

- wait_for:
host: server1
port: 3306
state: started
when: inventory_hostname == "server2"

- reboot:
when: inventory_hostname == "server2"



--
Kai Stian Olstad

Chris Bidwell - NOAA Federal

unread,
Oct 23, 2019, 9:53:04 AM10/23/19
to ansible...@googlegroups.com
Doesn't this use the ansible server running the playbook to check if the port is open?  

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9185fb2a-c8e8-3174-bba2-93a89f2bc71f%40olstad.com.


--

Chris Bidwell, CISSP
Space Weather Prediction Center
National Oceanic Atmospheric Administration
email: cchris....@noaa.gov
office: 303-497-3204
mobile: 720-496-3126

Kai Stian Olstad

unread,
Oct 23, 2019, 10:07:49 AM10/23/19
to ansible...@googlegroups.com
On 23.10.2019 15:52, 'Chris Bidwell - NOAA Federal' via Ansible Project
wrote:
> Doesn't this use the ansible server running the playbook to check if
> the
> port is open?

No, since host is server2 the wait_for module will run on that host.
You would need connection: local, delegate_to: localhost or hosts:
localhost to make it run on Ansible server aka Ansible controller.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages