# Which method use 'wait\_for' to check open ports?

**URL:** <https://forum.ansible.com/t/which-method-use-wait-for-to-check-open-ports/37712>\
**Category:** Ansible Project\
**Created:** [March 1, 2023, 7:00pm UTC](https://forum.ansible.com/t/which-method-use-wait-for-to-check-open-ports/37712 "2023-03-01T19:00:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leandro\_Montesoro](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@Leandro\_Montesoro](https://forum.ansible.com/u/Leandro_Montesoro)\
**Post date:** [March 1, 2023, 7:00pm UTC](https://forum.ansible.com/t/which-method-use-wait-for-to-check-open-ports/37712/1 "2023-03-01T19:00:58Z")

</div>

Hi !

i’m making a playbook like this:

- name: Check all port numbers are accessible from current host  
wait\_for:  
host: “{{ item[0] }}”  
port: “{{ item[1] }}”  
state: started  
delay: 0  
timeout: 3  
delegate\_to: localhost  
become: false  
ignore\_errors: no  
ignore\_unreachable: yes  
register: result  
failed\_when: not result.failed  
with\_nested:
- “{{ ansible\_default\_ipv4.address }}”
- [443,80,9200,9300,22,5432,6432]

The result informs that 1 of my ports in public ip it’s open, i’ll check in my host and its true, but it has an rule to drop all the trafic over port 22. Beyond it, the playbook informs ok, but when i’ll try to scan this por with nmap or telnet the result its the port its close. My question is ¿what is the method used for ‘wait\_for’ to check the ports?

thanks a lot !

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [March 1, 2023, 7:04pm UTC](https://forum.ansible.com/t/which-method-use-wait-for-to-check-open-ports/37712/2 "2023-03-01T19:04:58Z")

</div>

The code is open source. You can read the ansible modules on GitHub.

[https://github.com/ansible/ansible/blob/stable-2.14/lib/ansible/modules/wait\_for.py](https://github.com/ansible/ansible/blob/stable-2.14/lib/ansible/modules/wait_for.py)

Walter
