How to assert ansible.builtin.wait_for doesn't timeout?

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, setting a timeout, then asserting the task didn’t hit such timeout.
Inside ansible.utils.resolvable module docs, I saw assert can actually call another module and check its result:

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

Can I do something similar with wait_for, like this?

- 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!

No, assert can’t use a module. ansible.utils.resolvable is a test, not a module. See

shell> ansible-doc -t test ansible.utils.resolvable
1 Like

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

- 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 }}"

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:

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

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