# How to assert ansible.builtin.wait\_for doesn't timeout?

**URL:** <https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502>\
**Category:** Get Help\
**Tags:** ansible\
**Created:** [March 8, 2026, 6:29pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502 "2026-03-08T18:29:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EmersonPrado](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/emersonprado/32/10437_2.png) [@EmersonPrado](https://forum.ansible.com/u/EmersonPrado)\
**Post date:** [March 8, 2026, 6:29pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/1 "2026-03-08T18:29:52Z")

</div>

Hi all!  
I’ve been given a task of automating `rsync` transfers, and one of the requests is to validate port 22 conectivity. For that, I intend to use [ansible.builtin.wait\_for module](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/wait_for_module.html), setting a timeout, then asserting the task didn’t hit such timeout.  
Inside [ansible.utils.resolvable module docs](https://docs.ansible.com/projects/ansible/latest/collections/ansible/utils/resolvable_test.html), I saw `assert` can actually call another module and check its result:

```auto
- name: Validate DNS can resolve "{{ fqdn }}"
  assert:
    that: "{{ fqdn is ansible.utils.resolvable }}"

```

Can I do something similar with `wait_for`, like this?

```auto
- name: Validate port 22 accessibility in "{{ fqdn }}"
  assert:
    that: "{{ ansible.builtin.wait_for[...].result is not timeout }}"

```

Or should I define a variable or fact with `wait_for` result, then assert its value?  
Thanks!

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 9, 2026, 3:02am UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/2 "2026-03-09T03:02:37Z")

</div>

> [@EmersonPrado](#):
>
> I saw `assert` can actually call another module

No, `assert` can’t use a module. `ansible.utils.resolvable` is a [test](https://docs.ansible.com/projects/ansible/latest/playbook_guide/playbooks_tests.html#test-syntax), not a module. See

```console
shell> ansible-doc -t test ansible.utils.resolvable

```

---

<div class="post-metadata">

**Author:** ![EmersonPrado](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/emersonprado/32/10437_2.png) [@EmersonPrado](https://forum.ansible.com/u/EmersonPrado)\
**Post date:** [March 9, 2026, 4:47pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/3 "2026-03-09T16:47:06Z")

</div>

Thanks! So, when using a module, can I use assert to verify the task result, like this?

```auto
- name: Check port 22 connectivity in "{{ dest }}"
  ansible.builtin.wait_for:
    host: dest
    port: 22
    timeout: <Value>

- name: Validate port 22 connectivity
  assert:
    that: "{{ result is not timeout }}"

```

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [March 9, 2026, 5:17pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/4 "2026-03-09T17:17:50Z")

</div>

There is no test plugin called `timeout`, so that assert won’t work either. I’m curious why use an `assert` task at all? The `wait_for` task would fail like this:

```console
TASK [wait_for] *********************************************************************
fatal: [host]: FAILED! => {"changed": false, "elapsed": 5, "msg": "Timeout when waiting for dest:22"}

```

---

<div class="post-metadata">

**Author:** ![EmersonPrado](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/emersonprado/32/10437_2.png) [@EmersonPrado](https://forum.ansible.com/u/EmersonPrado)\
**Post date:** [March 9, 2026, 5:38pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/5 "2026-03-09T17:38:13Z")

</div>

Makes sense. I thought wait\_for would only return the result, not actually fail. Thanks for the correction!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 8, 2026, 5:38pm UTC](https://forum.ansible.com/t/how-to-assert-ansible-builtin-wait-for-doesnt-timeout/45502/6 "2026-04-08T17:38:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
