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